Do you work on projects in Visual Studio? Are you looking for a free and simple way to source control your projects without sharing them with the whole world? Would you like to be able to manage your projects online and still be able to work on your projects offline? If so, you may want to look into using Visual Studio and Git.
As a speaker and blogger, I create projects for demos, videos and screenshots. When I only had a few projects it worked quite well to “source control” my projects: I kept them in a OneDrive folder, created copies of demo code for new presentations and maintained versions manually.
However, the projects grew in number and size and became more difficult to maintain. There were no easy ways to track how I changed and improved my code over time, and I couldn’t revert to previous code. I kept telling everyone else to use source control, so I decided it was finally time to source control my personal projects.
In this post I will show you how I added my first project to source control with Visual Studio and Git.
Source Control Options
I mainly work with SSIS (SQL Server Integration Services) and Biml (Business Intelligence Markup Language) projects in Visual Studio 2013. I wanted a source control solution that supported SQL Server and Business Intelligence projects, that didn’t require me to install a lot of software on my laptop and that I could access and manage online.
The first option I looked at was the widely used and well-known GitHub. However, the free plan was only for public repositories. The cheapest plan with private repositories was $7 per month. I’m pretty sure that no one but me would be interested in my personal projects, but I didn’t like the idea of making my cluttered work-in-progress code public.
After searching for GitHub alternatives, I looked at GitLab.com. It sounded good at first: “GitLab.com hosts your (private) software projects for free.” Unlimited private repositories, completely free. There was just one little thing: They clearly state on their front page: “Disadvantages: Right now GitLab.com is really slow.”
Then I looked at BitBucket, a popular option that is free for small teams up to five users. I use Atlassian’s other products (JIRA, Confluence and HipChat) at work. They are very powerful tools, but they sometimes feel a bit clunky. The desktop client SourceTree had that same clunky feeling to me.
Visual Studio Team Services
After looking at GitHub, GitLab.com and BitBucket, I realized that deep down I was really just looking for something similar to Team Foundation Server that I use at work. I already knew how to use it, it is integrated in Visual Studio, and the lazy developer in me didn’t really want to learn a whole new interface.
I found out that Team Foundation Server Express is free for five users, but even better: they have a hosted service called Visual Studio Team Services. “Five users free, unlimited private repos, developer tools, training and support”? Dear Microsoft, I knew you had moved towards a more open-source community, but I was slow. I didn’t realize just how much you offer to developers who want to work with your products. Thank you!
I finally decided that Visual Studio Team Services was the right source control option for me.
Setting up Accounts and Software
Visual Studio Dev Essentials Account
If you don’t already have a Visual Studio subscription, join the Visual Studio Dev Essentials program. You will get many benefits, including:
- Visual Studio Community
- Visual Studio Code
- Visual Studio Team Services
- $25 Monthly Azure Credit
- Office Online Free Plan
- Power BI Free Plan
- 6-Month Pluralsight Subscription
And much, much more. I have only listed what is relevant for me as a Data Warehouse and Business Intelligence developer. If you are an app developer, you have many other benefits waiting for you :)
Team Explorer for Visual Studio
If you don’t already have it installed, download Team Explorer for Visual Studio. I had to download and install Team Explorer for Visual Studio 2013:
Visual Studio Team Services Account
Go to Visual Studio Team Services and create your free account.
Create your site URL. If you live outside the US, you may want to click Change details and host your projects in another location. (At the time I am writing this you can choose between South Central US, West Europe and Australia East.)
Creating your First Team Project
If you click on Add Code in the popup, you will be taken to a new page. From this new page you can click Clone in Visual Studio to launch Visual Studio. You can also go to your overview dashboard and click Open in Visual Studio to launch Visual Studio:
Working on your Project in Visual Studio
Tip: I was not familiar with Git concepts. If you are new to Git as well, you may want to read the Git documentation or check out the Using Git with Visual Studio 2013 Jump Start on Microsoft Virtual Academy before continuing in Visual Studio :)
Configure user settings
If this is the first time you use Git on your computer, you will have to configure your user name and e-mail address. Click Changes, click Configure, verify your user settings, and click Update:
Included Changes, Excluded Changes and Untracked Files
If you have used Git on your computer before, you will not have to configure your user name and e-mail address again. You will see the included changes, excluded changes and untracked files in the Team Explorer. What you see depends on your project. In my case, the generated .user and .suo files were untracked, while my other project files were included:
If your files are untracked, you need to add them to the included files before they can be committed. To add your entire project, click Add All. You can also right-click on the project and click Add, or even click and drag the project to Included Changes. The files are now included and ready to be committed. You will see the change type next to the file name, in my case the change is [add]:
There are three types of commits:
- Commit – Commit changes to local repository
- Commit and Push – Commit changes to local repository, then push changes to remote repository
- Commit and Sync – Commit changes to local repository, pull changes (if any) from remote repository, then push all changes to remote repository
Since I work alone on my projects, I don’t have to worry about pulling changes from other team members. This simplifies my commit process. The main thing that made me choose Git over other source control systems is that I can commit locally when I’m offline, and then push and sync when I’m online. It is extremely fast, and I can work just as well on an airplane as in my office :)
View and Compare History
There are many ways you can view and compare history, both in Visual Studio and in Visual Studio Team Services.
View and compare history in Visual Studio
In the Team Explorer, you can click Actions and then View History. In the Solution Explorer, you can right-click on the project or a single file and then View History:
If you View History for one file, you will see the commits, the commit message, the commit number, who committed and when the commit was made. (You will also see the branches, in this case master, but I will not cover branching and merging in this post.) You can right-click to Compare with Previous:
When you compare with a previous version, you will see what has changed. In this example, the code marked with red has been removed, and the code marked with green has been added. On the right side you will see a navigation pane that shows where in the code something has changed:
In this post I added my first project to source control with Visual Studio and Git. I showed how to set up a Visual Studio Team Services account, how to create a Team Project, how to work with Git in Visual Studio, and how to view and compare history in Visual Studio and in Visual Studio Team Services.
I did not cover Git commands or branching / merging in this post. I also did not cover all the features in Visual Studio Team Services. There are simply too many things to cover in one blog post! I recommend that you just start using Visual Studio and Git, and experiment and dig into all the great features. Some of my main resources are listed below :)