Blog

Getting started with GIT and Visual Studio


We're a very small company, with one or sometimes two developers. In the past, we've relied of common sense and a file-based system for version control. Recently, it's become clear that we could benefit from the facility to branch features without affecting the master.

Visual Studio 2017 added GIT integration, and we've signed up to Azure DevOps to host our projects in the cloud. Now we need to get a lot of existing projects into our local repo, then load them into the cloud. If you know how to do things in the correct order, you'll be less likely to get unwanted outcomes.

So this blog is for Visual Studio users applying GIT version control to their projects for the first time. The objective is to load the files you need into the cloud, and not to load files which aren't part of the project. We won't be using the command line, just the tools available in Visual Studio.

Start by creating a project in Azure DevOps. This means that you'll be able to set the Work Item Process rather than have DevOps make a guess that you might regret later.

Create a project in Azure DevOps

 

Your next step depends on whether your project has GIT version control applied or not.

 

If you created it as a new project in VS 2017, you'll probably have GIT set up, even if you haven't used it yet. The bottom right of your Visual Studio window will look like this:

You might have GIT set up

 

You might expect the GIT file structure to mirror your Visual Studio project structure. IT WON'T. It mirrors the file structure under the project root. So crucially, your next step will be to edit .gitignore. In Team Explorer click the home icon, then click Settings, Repository Settings and open the ignore file for editing. Visual Studio provides a template which excludes a lot of temporary files - you'll want to add the files which are in your project folder but which you don't want to include in your GIT. 

 

Edit your .gitignore file

 

You can now commit your changes to your local GIT.

 

Once that's done, publish the repo to Azure DevOps. Remember to click "Advanced" so you can choose the Project you created at the beginning of the process.

You should now see your project in Azure DevOps, with only the files you want.

Your project in Azure DevOps

 

On the other hand, if you don't have GIT set up, you'll see the "Add to Source Control" message in the bottom right.
Click on that, then choose GIT. All of your files will be added to your local GIT, so now you need to remove them.

 

You might have to add the whole project as a first step

 

Open .gitignore as before, and add the files and folders you want to exclude. Save the file. Now remove all of those files and folders from your project folder - just drag them to a temporary folder which isn't below your project folder.

 

Commit that change to your local GIT.

Once that's done, publish the repo to Azure DevOps. Remember to click "Advanced" so you can choose the Project you created at the beginning of the process.

You should now see your project in Azure DevOps, with only the files you want.

Reading back, this seems like pretty elementary stuff - but if I'd had this information a week ago, it would have saved a lot of time.