Using Git With Visual Studio

I am starting to use Git with Visual Studio 2013 on my home projects.  I have been using Git lightly for pushing code samples into GitHub, but never on projects with other people.  This is a pretty good set of articles about setting up Git with Visual Studio and well worth the read before doing it (like who reads instructions). 

I created a project on Visual Studio Online and selected Git as the source control.  I then cloned the empty project locally.  Next, I created a brand-new Web Api 2 solution in Visual Studio and pushed the files over to that repository.  I then pushed those changes up to VSO.  Finally, I went over to another machine and cloned the repository and pulled down the files.

This was all well and good until I made a change on one machine and I wanted to pull down the changes into the solution that I had open on the other machine.  I was getting an “uncommitted changed being overwritten by merge” exception.  The frustrating thing was that there was nothing in the Visual Studio 2013 tooling/add-ins that allowed me to discard my local changes.  I wrote this post to stack overflow and it turns out I had a problem because I made the mistake of adding file to the repository that I didn’t want to.  I needed to do this –> add the .suo file to gitIgnore BEFORE committing the 1st change.  The problem was that adding it to the gitIgnore after the commit means the file was still being tracked and there is nothing in the out of the box VS2013 tools that can help you resolve the problem. 

The best advice from SO was to use git extensions because when I installed it, I could do all of the things I wanted to do without learning the git commands.  Indeed, I installed it and holy cow, this is awesome:

image

Advertisements

One Response to Using Git With Visual Studio

  1. Rob Seder says:

    Jamie,

    For what it’s worth, I found this whole thing is “easier” if you have a branch, per machine. Make all your changes on your local branch, then when you are done, merge that branch with the “master” branch.

    When I do it this way, it’s almost never problematic and I can do everything withing Visual Studio. See this blog post:

    http://blog.robseder.com/2014/11/13/how-to-set-up-version-control-branches/

    HTH

    -Rob

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: