Table of contents

Share your code with Git and Visual Studio

Last Updated: 8/4/2016

Team Services | TFS 2015 | Visual Studio 2015 Update 2 | Previous version

No matter the size of your Visual Studio project or how far it is into developement, you can easily share it in a Team Services Git repo.

This content walks you through the steps to get your Visual Studio project into a new Git repo in Team Services. If you already have your project in Team Services, you can use the Git quick start.

Create a local Git repo for your Visual Studio project

Create a new local Git repo for your project by selecting Publish to Git from the Visual Studio Status bar on the status bar in the lower right hand corner of Visual Studio. This will create a new repo in the folder the solution is in and commit your code into that repo.

Once you have a local repo, select items in the status bar to quickly navigate between Git tasks in Team Explorer.

Visual Studio Git status bar


  • Visual Studio Unpublished Changes Status Bar icon shows the number of outgoing commits. Selecting this will open the Synchronization view in Team Explorer.
  • Visual Studio Pending Changes Status Bar icon shows the number of uncommitted file changes. Selecting this will open the Changes view in Team Explorer.
  • Visual Studio Repo Status Bar icon shows the current Git repo. Selecting this will open the Connect view in Team Explorer.
  • Visual Studio branch status bar icon shows your current Git branch. Selecting this displays a branch picker to quickly switch between Git branches or create new branches.

Publish your code

  1. In the Sync view in Team Explorer, select the Get Started link under Publish to Team Services.

    Publish your code from VS directly into Team Services

  2. Verify your email and select your account in the Account Url drop down.

  3. Enter your repository name and select Publish Repository.

    Publish your VS project to a new Team Services Git repo

    This creates a new Team Project in your account with the same name as the repository. To create the repo in an existing Team Project, click Advanced next to Repository name and select a team project.

Your code is now in a Team Services repo and your local repository can push and pull updates. You can view your code on the web by selecting See it on the web .

View your VSTS Git repo on the Web

Commit updates

  1. As you write your code, your changes are automatically tracked by Visual Studio. You can commit changes to your local Git repository by selecting the pending changes icon Visual Studio Pending Changes Status Bar icon from the status bar.

  2. On the Changes view in Team Explorer, add a message describing your update and commit your changes.

    Add a comment and choose Commit

  3. Your changes are now committed into the local Git repository.

    Your changes are now committed

Sync changes

As other team members update the code in the repo, you'll need to sync their changes with your own code.

  1. From the Sync view in Team Explorer, fetch the commits to view changes that your team has made. Double-click the commit to view the list of files changed.

    Fetching changes does not merge the commits into your local repository. You will need to pull the changes to merge them into your local repository.

    Choose Fetch to see any changes that your team has made

  2. When you're ready to merge the changes with your local repo, Sync the changes to push your commits and pull changes from others.

    Choose Pull to get these commits locally

  3. The changes from your team are now in your local repository.

    The changes are now in your local repo

Try this next

Learn more about using Git in the Git tutorial and create a build for your project code.

Q&A

Q: I don't see the Publish button in the status bar.

A: The Publish link in the status bar was added in Visual Studio 2015 Update 2.

If you are in a previous version of Visual Studio, create a local Git repo for your project by selecting the Create new Git repository option in the New Project window when you create a new project.

You can create a local Git repo for an existing solution by right-clicking your project in the Solution Explorer and selecting Add Solution to Source Control.

Q: How can I see what changes are in a commit before I pull it into my local repo?

A: To see what's changed in a commit, go to the Syncrhonization page in Team Explorer and right-click on the commit. Select View Commit Details. You can then right-click on any file modified by the commit and select Compare with Previous... to view the changes compared to the previous version of the file.

Choose Compare with Previous from the context menu

Q: How do I associate my commits with work items?

A: You can include work items in your commits through Related Work Items in the Changes page in Team Explorer.

Adding work items to changes

Work items can be included in commits by adding #ID into the commit message. For example, "Fixing bug #23 in the reporting tools" would link work item 23 to the commit. The work item is linked when the commit is pushed to Team Services.

Q: Can I use Git command-prompt tools?

A: Yes. See the Git workflow tutorial for help with using Git from both the command line and Visual Studio.

© 2016 Microsoft