Git- Integration With Visual Studio 2013
In my previous post, I did an intro to Git, what it is, what the basic commands are in the Command Prompt, and the general cycle of adding and committing files. In this post, I want to show how Visual Studio 2013 integrates Git into the IDE. This way, you are not responsible for manually opening up the Command Prompt and making commits. Visual Studio can make this easier and quicker for you. So, let’s go ahead and get started. If you would rather watch this in video form, you can use this YouTube Video.
First off, if you don’t have Visual Studio 2013, you download VS Express 2013 for free here. If you have a Bizpark account, Dreamspark account, or MSDN Subscription, you can also download Visual Studio Ultimate, Professional, etc. here. I won’t walk through the installation process here, but If you are installing Visual Studio for the first time, just know that the process is pretty straight forward.
Now that we have Visual Studio installed, we can start by creating a new project. To do this, open up Visual Studio, and go to File->New->Project. I am going to create a new Universal Project under visual C#, but it doesn’t matter what kind of project you create. The main thing to notice when your new project however, is the checkbox that asks whether or not you want to use source control in the bottom right hand corner.
You could go ahead and check the box, “Add to Source Control”, but for this example I am going to skip this for now. If you did however, this would initialize your project as a Git Repository. This accomplishes the same thing as using the “git init” command in the command prompt. Again, this is helpful because you wouldn’t have to manually open up the Command Prompt and do this yourself. I did say I was going to skip this for now, so I will create my project without selecting this check box.
I wanted to skip that check box for now to simply show you that you can add your project to source control at any time. This means you can take any existing project and add to source control. To do this, go to File->Add to Source Control. After doing this, you will see a pop up menu asking which kind of Source Control you want to use, Team Foundation Version Control or Git. Since this article is about using Git, let’s go ahead and choose Git and then click OK.
What we have done is created a Git Repository for our project. Perfect. Now you could make changes and edit files in Visual Studio, but how do you make the actual commits? Remember the cycle we want to follow, Create/Edit Files->Add->Commit. . Let’s see how to make commits.
In Visual Studio, you want to find the Team Explorer window. You can find this under the View tab at the top. Once you pull it up, it should look like this.
From here go ahead and click on your Git Repository. Mine is shone at the bottom of the above screenshot and is called App1 (a terrible naming convention I know). After opening up that repository, you should see this.
From here, click on “Changes”.
You should see a whole list of files that are ready to be committed. You will also see a folder for Included Changes (this currently includes all of my files) and a folder for Excluded Changes. You can choose which files get included in the commit and which ones don’t if you choose. This would be the equivalent of only adding certain files with “git add” before committing. Selecting which files to include is more or less the “Add” portion of our commit cycle.
In addition, you should see a grayed out “Commit” box right under the Changes heading. This box is grayed out because we need to a description of our commit to be able to commit. This text box is shown above with the temporary text saying “Enter a commit message <require>”. If you go ahead and enter a message, say “initial commit”, the Commit box will become enabled.
Now that the Commit button is enabled, you can click it to commit all of your files. After committing, notice that there is no longer a list of files that have been changed and need to be committed.
So that covers that basics of using Git integration in Visual Studio 2013. This is very useful because it takes away the need from you to have to manually open up the Command Prompt and give Git commands. Especially nice if you don’t like using the Command Prompt in general. Either way, knowing the basic command line commands is not a bad idea.
If you would rather watch this in video form, you can find the YouTube video here.
As always comment below with questions, comments, or concerns, or find me on twitter @jquickwit. Thanks!