Subscribe to Sergio Tapia - Lost in the GC.        RSS Feed
-----

Visual Studio 2010 | Mercurial | BitBucket - Complete Workflow Tutorial

Icon 1 Comments
In this tutorial, I'm going to teach you how to do the following:

  • Installing Mercurial on Windows 7.
  • Installing TortoiseHg on Windows 7 (for icon overlays and the workbench).
  • Installing the VisualHg Visual Studio 2010 addon.
  • Committing your code locally on your machine's repository.
  • Pushing your code to a remote location, BitBucket.


Ideally, by the end of this tutorial you will find yourself comfortable with this workflow and start committing early and committing often. :)

Installing Mercurial on Windows 7.

This is probably the easiest part. Just visit the official Mercurial Website and click the big fat download button. After that double click on the installer you just downloaded and follow along the installation Wizard. Nothing out of the ordinary will pop up (unlike Git's awful putty and bash sequences).

Posted Image

Restart your computer for good measure and then open up a command prompt. Type in hg help and you should see this:

Posted Image

If you see the same thing, Mercurial has now installed correctly on your machine.

Installing TortoiseHg on Windows 7

TortoiseHg provides you with a lot of graphical tools you can use to manage your local (and remote) Mercurial repositories. It also gives you a series of overlay icons that show up on your files, indicating whether everything is committed to the repository or you have changes pending.

Posted Image

To download TortoiseHg, visit the official website and following along the installation wizard. After you're done reboot your system.

After the reboot try right clicking on your desktop. You should see something like this:

Posted Image

Great, so far you have Mercurial and the tools to make your life as a developer easier.

Installing the VisualHg Visual Studio 2010 addon.

VisualHg is an addon that provides you with a helpful toolbar baked into Visual Studio 2010. No more excuses for not committing code. Just tap that button. :)

Posted Image

There are two ways to install the addon, via the Website or via the Visual Studio Addon Explorer.

We'll install it via the website. Just visit it's official CodePlex site and download the extension. Installing it is a matter of double clicking the file and clicking Accept.

Committing your code locally on your machine's repository.

So now that everything's setup, let's create a brand new project and start working on things.

I've created a brand new MVC3 project, set up different projects within the solution.

Posted Image

Now that your solution (and projects) skeleton is in place, close Visual Studio 2010 and navigate to your projects folder.

Posted Image

Right click, and click TortoiseHg > Create Repository Here. This is just a GUI wrapper for the hg init command.

Posted Image

Make sure to tick the Show In Workbench button.

Posted Image

This is the main workbench. TortoiseHg will show you a pane of modified files and allow you to tick which ones you want to handle. Let's go ahead and select everything by ticking the topmost checkbox and type in a little commit message. You'll be asked if you want to add the new files Mercurial is tracking. Click Yes. After clicking commit, everything is set. You've done your first Mercurial commit! :)

Quote

Site Note: Make it a habit to always leave a meaningful commit message when working with source control. It helps you know what changed at what point and find the exact revision you're looking for. Commit early, commit often.


Posted Image

Now open up your Visual Studio project again, and notice the Solution Explorer. Now there are little icons showing you what's the current status of a file.

Posted Image

As you can see, there are some orange icons. This is because there are pending changes. Let's click on the commit button that VisualHg gave us.

Posted Image

Click commit, we're done. You're now using Mercurial to track changes. :)

Pushing your code to a remote location, BitBucket.

Create your account over at BitBucket, then create a Repository. The menus are very easy to navigate so I won't talk about that aspect.

After you've setup your repository on their website.

Go to your projects folder and right click, select "Workbench". Click on the synchronize button. You should see the following:

Posted Image

Select https, and type in the hg push url BitBucket gave you for your project.

Posted Image

After typing in the URL for your online repository, click on the Push icon to push your changes over to BitBucket.

Posted Image

You'll be prompted to type in your BitBucket username and password, and after that your code will be surfing through the intertubes.

Final Thoughts

Using Source Control in your projects will change the way you feel about exploration. No more worries about breaking the build or doing something you should be doing. All it takes is a revert and you're done, back to happyville.

I've been using Mercurial (nothing to fancy mind you...) for about a year now and I love it. It's fast, friendly and works well on Windows. I hope you enjoy it as well.

Other considerations you might want to look into are .hgignore files. These files are used to tell Mercurial to ignore certain file extensions. For example, you don't want to track compiled .dlls, so you create a rule in the .hgignore file and mercurial will no longer track ANY changes on those files from that point on.

Remember this is the workflow you should be trying to aim for.

  • Code code code, committing to your machines repository as needed.
  • Once you have a working bit of code, a module so to speak, push your changes online for other team members to consume.

1 Comments On This Entry

Page 1 of 1

Sergio Tapia Icon

20 August 2011 - 02:13 PM
If you use Mercurial, this is also Mandatory Reading! :)

http://hginit.com/
0
Page 1 of 1

Trackbacks for this entry [ Trackback URL ]

There are no Trackbacks for this entry

2 user(s) viewing

2 Guests
0 member(s)
0 anonymous member(s)

About Me

Posted Image


Bienvenidos! I'm a USA ex-pat living in Bolivia for the past 10 years. Web development is my forte with a heavy lean for usability and optimization. I'm fluent in both English and Spanish. I guest write for the popular Python website Python Central. Visit my website.

Categories