Sync local source code and commit history with Visual Studio Team Services

In previous blog post, we learned how to do baby steps for implementing IaaC. We learned how to use ARM templates, Git and Visual Studio to code your subnets in the Azure. Now, there is no doubt that Git has taken over the world for source code management. And while it is good for managing versions of source code, those versions and details are confined to your local machine. If someday your local machine goes kaput, its all in water. For that, you need to sync your changes to a centralized source code management system. Also having centralized source code management allows more than one person to work on the same repository.

This is where Visual Studio Team Services come into play. It is a Software as a Service aka SaaS offering from Microsoft which does a whole lot of other things as well. In this blog post, we’ll learn how to sync your local source code along with all the commit history with the Visual Studio Team Services.

Do note that you can use any git based centralized repository like GitHub, BitBucket, etc by using the same principles as mentioned in this blog post.

First of all, we need to sign-in inside Visual Studio Team Services or VSTS with an account. If you don’t already have a one, you can easily sign up for one. Once we have signed-in, we’ll create a new project from Dashboard:

Select new project inside VSTS
Select new project inside VSTS

It will ask for few basic details such as what type of project management and repository type you would need etc. Fill in the details as shown:

Submit details for new project
Submit details for new project

It will automatically create a source code repository with same name as the project, by default. If you already have a repository, to which you would want to push your changes, you can skip above steps. We only need to copy the repository URL from the source code repository created and keep it for later.

Now, we’ll need to open existing Visual Studio project and then select team -> manage connections from the tabs as shown below:

Select Manage connections from Team tab
Select Manage connections from Team tab

Once its selected, we need to provide sign in information for the VSTS subscription. Now, from the Team explorer pane, select settings -> Repository settings -> Remote section, select add and provide details for the centralized repository and save it:

Submit repository settings
Submit repository settings

Make sure to select the name as origin.

Also, we need to go to Team explorer pane -> settings -> global settings and select check box for ‘Enable push –force’ and save it. This is needed so that first time, we can push forcefully source code into remote repository.

Now, from the team explorer pane, select ‘Sync’ and then select Push:

Push the code changes
Push the code changes

Once the push is complete, you can then see the source code is successfully uploaded to the VSTS:

VSTS code view after submitting push --force
VSTS code view after submitting push –force

This will sync all your commit history into VSTS and from then, you can manage your changes from both inside VSTS as well as Visual Studio.

4 thoughts on “Sync local source code and commit history with Visual Studio Team Services

Leave a Reply

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

You are commenting using your 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 )

Connecting to %s