Up and Running with GIT and Visual Studio

This is just a quick guide for those on windows using Visual Studio and wanting to start tinkering with GIT. If you want to know why Git is better than (Insert source control management system here), click this link. Or, if you more in the mood to hear why every other source control system in the world sucks, check out this video from Linus Torvalds who wrote GIT.

First, Git is new as of a few years ago and so the tooling support isn’t phenomenal. That being said, you need to start with by installing msysgit:

Obviously, windows version, download, install, all that good stuff. At this point, you could start using Git as this will install the windows command line tools to do so. However, a command line doesn’t completely cut it for me, and if your reading this, your probably not interested in what I’m writing anyways, so why are you here?

Moving on.

Now that the Git command line tools are installed, You’ll want to install GitExtentions, available here:

This will install tooling support into Visual Studio and also install windows explorer shell extensions and puts a few things into the explorer. Once you run it, you’ll quickly notice that your probably missing a diff tool. You can either install KDiff3 or your own diffing tool. Your preference. If you also don’t have a good text editor (Notepad doesn’t count) I recommend also getting Notepad++ and installing that as well.

Go into settings, and setup your settings to look something like this:

You now have GIT installed. Congradulations!

Now what?

Git 101.

Ok, I’m going to assume you’ve already had some experience with a source control management system of some kind or another (svn, tfs, etc…) before I jump into this. First, everything is local. When you start adding other people or services like GitHub, you realize that your local repository is a branch, and merging involves pulling in changes from other branches, but I digress.

Lets start off with a simple hello world project. Go into visual studio, create a new console project, give it a directory and start it up. Now, to create the repository find this little bar and click on the little folder icon that says ‘browse repository’. (Alternatively, you can simply directly select ‘Create new repository’ from the Git menu in visual studio)

Which will open this:


From here, select create new repository, if you allowed Visual Studio to create a directory for your project you’ll want to create the repository one directory down since every file in that directory and any sub directory (besides any listed in the .gitignore file) will be source controlled.

On the next page, I recommend clicking on ‘Edit .gitignore’ and copy the recommended list (this will cause git to ignore any files or directories that match this list).

You now have a repository, well on your way to rocking a Git controlled project. Finally, committing files. So go in make your project spit out hello world to the console, and hit commit. You’ll have the following window (Except that the changed files will be in the top left box, select which files you would like to commit, press add, and then it will look like the window below):

Select all the files in the Working Directory window, click stage, enter a commit message, hit commit, ok, and done! You’ve now made your first commit.

Now, this is something I didn’t understand right off the bat, when you open up this window everything that is different is listed in the working directory changes window, anything that has changed or is different from the previous version that isn’t in the .gitignore file. Now, to commit something, you ‘stage it’ which takes the current version of whatever file you select and puts it in the staging area (this allows you to make sure your only committing what you want to commit, because there’s many cases where you want to break up your commits into subsets of the entire change list) and commit will only commit those files that are in the staging area. If you go back to the ‘browse repository’ you’ll see something like this (I’ve added several commits):

There’s a lot more I could get into, and I may at some point, but this ought to get you on your way, feel free to leave questions in the comments, tell me where something in this post is wrong or outdated and so on.

Happy Git’ing

7 thoughts on “Up and Running with GIT and Visual Studio

  1. Pingback: GitHub 101 on Windows « Paul Rohde

  2. Hi,

    I am new to Git. I follow your instruction and everything works well until the part after doing the Hello World example. When I tried to commit, I cannot see the file changes shown on this image: http://media.paulrohde.com/blog/2010/10/GitExtensionsGitCommit.png

    It looks like when I initialize the repository, it does not even know what files are in there.
    Is there something that I did wrong? I am using the latest version of Git, 5.8.7.

    Any advice will be very helpful.

    • Ahh, your right, this is a bit of a failing on my part. After you’ve completed the instructions for editing the Git ignore file, and hit commit, the files will be listed in the top left window. In Git, this is where any untracked files are shown. In order to commit files, those files first have to be staged (all this does is allow GIT to know which files you want committed since it can’t assume you want every single file committed every time). After you stage all the changed files, the screenshot will look like the one up above, and you can then commit. Its also why your getting the error in your other post, its because Git thinks your trying to ‘commit’ without any changes.

      I’ll see if I can get the post updated with another image and add those instructions in. Thanks for pointing it out!

  3. I keep getting this error message:

    # On branch master
    # Initial commit
    # Untracked files:
    # (use “git add …” to include in what will be committed)
    # .gitignore
    # HelloGit.sln
    # HelloGit/
    nothing added to commit but untracked files present (use “git add” to track)

  4. Ok I get this, but what if you publish your project to a central server and someone pulls it down?

    Thanks to .gitignore, the other programmer can’t fetch it. So he only has the .cs files, but no .sln, …

    So he can’t open it from his folder in visual studios.

    How do you make sure that all those compiled files are given to the other developpers?

    • You shouldn’t be adding your solution or project files to .gitignore since you always want changes to those files to be tracked as well. Anything you want tracked should NOT go into the .gitignore file. If your using git extensions and you use the prepopulate option to add default ignored files to the .gitignore it will not add in the project file.

      Hope that helps, best of luck.

  5. I get this error while starting visual studio 2008. how to fix this?
    Microsoft Visual Studio
    The Add-in ‘Visual Git’ failed to load or caused an exception.
    Would you like to remove this Add-in?
    If you choose yes, the file it was loaded from, ‘C:\Users\sandesh\Documents\Visual Studio 2008\Addins\GitPlugin.AddIn’, will be renamed.

    Error Message:
    Error number: 8013101b
    Yes No

Leave a Reply

Your email address will not be published. Required fields are marked *