Distributed Version Control System

Over the past decade or so there has been an exponential rise in the usage of Distributed Version Control System (DVCS). This post is about my experiences in using GitHub and Bitbucket distributed version control systems. I would like to share my experience in setting up the systems on a Windows 7 PC.

GitHub & BitBucket

There is already so much information available on the history and evolution of Version Control Systems that I would not like to repeat it myself. There has been lot of talk off late about the Distributed version control systems. Initially these DVCS were considered to be mostly suitable for Open Source projects. Recently I was part of a group discussion where one of the member suggested using DVCS in an enterprise application. The advantage offered by DVCS was the ease of merging and better support for branching. Although we did not progress much on that discussion, it was worth noting that there are other enterprises who are using this approach and leveraging the benefits offered by DVCS systems.

I was looking for some means of storing the source code I use for my blog entries in the file sharing systems over the internet. I have been using Dropbox for long time. The problem with Dropbox is that it is a file sharing system and not a source control repository. Apart from the blog source codes, I also have some personal projects which I keep updating with the changes in technology. This is where I found GitHub useful for storing the source codes.

GitHub

GitHub is built on top of Git and offers various pricing options. It is free for open source projects. You can store your code as open source in GitHub repositories. GitHub promotes itself as social coding website. There are various GUI based clients for Git on Windows. Here is a link which gives a step by step guide to setting up GitHub and in turn Git on a Windows PC.

There are different ways of working with a DVCS on your PC. If you are a geek and like to work off the command line, you can work with GitHub using the shell. Unfortunately I am not a command line freak and prefer to have a GUI to work with GitHub. There are multiple options available. I have tried the Msysgit Git GUI and TortoiseGit. Msysgit comes bundeled with the Git installation package. TortoiseGit is a port of TortoiseSVN for Git.

Setting up GitHub can take up some time. After installing the software you need to set up the RSA keys. If you are unable to set up the keys correctly you’ll not be able to store anything in GitHub. Once the Git software is installed on the PC we are ready to create Repository and push the changes to GitHub. These are the steps I undertake to setup new repository in GitHub. I’ll skip the steps related to registration with GitHub as it is one time activity. Assuming you are a registered GitHub user these are the steps to follow.

1 – Create a new Repo in GitHub

Git Homepage

We can create a new Repository in GitHub using any one of the highlighted options in the above screenshot. You can use the Create a Repository link under the Bootcamp section as indicated by 1 or the link under Welcome to GitHub indicated by 2 below the bootcamp section. There is also a New repository button next to Your Repositories. This is indicated by 3 or using the Create new repo button at the top right of the page as shown using 4. Except the first link all other redirect us to the repository creation page as shown below

Create Repository Screen

I want to add one of the directory containing source code available on my hard disk to GitHub. I created a repository named DecoratorDesignPattern

decorator repo on GitHub

Note the three highlighted areas in the above screenshot. At the top of the page we have the URL to the newly created repository. We can use one of the options from 2 or 3. If we are starting from scratch we can use the create new Repo on Command line option. If we have created the repository on the local hard drive we can use the third option that of pushing an existing repository from command line.

2 – Create new repository on command line

I need to set up a local copy of the remote repository. So I’ll use the Create a new repository from command line option. In Windows Explorer navigate to the directory where you wish to create the new repository and right click on the folder.

image

From the context menu select Git Bash Here option. It opens up the Git command prompt. Type the commands as shown in the previous screen

image

Please note that the GitHub url is case sensitive. After the repository is created, we can push the changes to the remote server. If everything goes fine you should be able to see a screen as below

image

With this step we have successfully pushed the contents of the local folder to a remote repository. If you don’t want to use the command line tools, you can use the GUI tools. Here is a screenshot of the default GUI provided by Git.

Git Gui Context Menu

Right click on the directory in Windows Explorer which contains the Git repository and select Git GUI Here option from the context menu. You’ll be able to perform all the operation that we performed using command line from the GUI as well.

Git GUI

The Git GUI is good option to start with. There are other client softwares which allows us to work with Git using GUI. I have also used Tortoise Git. This client offers much more options in the context menu as shown in the screen shot below

tortoise Git GUI

One of the major limitation of GitHub is that all your repositories will be public if you don’t want to subscribe to their monthly or yearly plans. As always now a days there are alternatives available and at times you are spoiled for the choices. Recently BitBucket started a service similar to GitHub with DVCS support.

BitBucket

It has support for multiple DVCS systems including Git and Mercurial. There is also an option of importing existing repositories from other providers like GitHub. The advantage it has over Git is that you can have unlimited number of private repositories. The process of setting up the system is also simpler compared to GitHub. You can follow the steps in this post to set up Bitbucket repository with either Git or Mercurial as DVCS. If you choose Mercurial as the option the download comes with a full featured Tortoise Hg GUI.

The steps for setting up a Mercurial repository and storing it remotely are relatively simple compared to Git. The link related to setting up of Bitbucket talks about creating new repository so I would not like to repeat it again. Following is the screenshot of the Tortoise Hg client for BitBucket

Tortoise Hg client

We can use the dashboard in the Bitbucket web site to create new repositories or import existing repositories from other sources like GitHub

BitBucket dashboard

Currently there are multiple sources supported by BitBucket to import your existing code as shown below

Bitbucket Import repo

Current support is provided for CodePlex, git/GitHub, Google Code, Mercurial, SourceForge and Subversion repositories. You can choose either Git or Mercurial as the target type and also make it a private repository.

Conclusion

Not everybody can afford to invest in a full fledged source control system. If you are in a small start-up or a individual freelancer, using these systems can help you to leverage the facilities of commercial SCM. As for me I use multiple laptops and copying files across multiple devices can be avoided using online storage. It also helps me maintain the history of changes even for a personal projects using lightweight version control system. I can now keep copies of all my trial projects in a central repository. Apart from the source code related to my blog posts, I can also store my personal projects as private repositories using BitBucket.

With DVCS you have a local copy of the repository. The speed is an advantage. These are designed for speed. After the repository is cloned from the central server, we do not need connection to central server. Operations like comparisons and version history can be done without network connectivity.

Until next time Happy Programming.

Further Reading

Based on the topics discussed in this post I would like to recommend following books as further reference.

Share:
spacer

6 comments:

  1. Have you tried GitHub for windows? It is an excellent client for GitHub. It makes lot of things like SSH keys transparent to you. It is really a no brainier to use for .net developers.

    ReplyDelete
    Replies
    1. hi Manoj,
      I did notice the GitHub for Windows while writing this post. Unfortunately I did not get enough time to experiment with it. It was not available while I started using GitHub about 7 months back. Thanks for mentioning it. I'll definitely look at it in future.

      Delete
  2. how about TFS Service and Tfs express... its free and is integrated with Visual Studio...

    ReplyDelete
  3. I agree with you manoj that github is best option.

    ReplyDelete
  4. I am very interested in. May I ask to spoon feed the detail please?
    cheap windows vps

    ReplyDelete
  5. How use github repo and Visual Studio 2013 ?

    ReplyDelete