Share your code with Azure Repos and Visual Studio

Azure Repos | Azure DevOps Server 2020 | Azure DevOps Server 2019 | TFS 2018-TFS 2015

Visual Studio 2019 | Visual Studio 2017 | Visual Studio 2015 | Visual Studio 2013

This article walks you through the steps to get a Visual Studio solution on your PC into an Azure DevOps Git repo you can share with others. If you want to work with a Visual Studio solution hosted in an existing repo, see the Git tutorial.

Note

Visual Studio 2019 version 16.8 and later versions provide a new Git menu for managing the Git workflow with less context switching than Team Explorer. Procedures provided in this article under the Visual Studio 2019 tab provide information for using the Git experience as well as Team Explorer. To learn more, see Side-by-side comparison of Git and Team Explorer.

Prerequisites

  • Repos must be enabled on your project. If the Repos hub and associated pages don't display, see Turn an Azure DevOps service on or off to reenable Repos.

  • To view or contribute to code, you must be a member of an Azure DevOps project with Basic access or higher.

    • If you don't have a project, create one or sign up for free.

    • If you aren't a project member, get added.

      Note

      For public projects, users granted Stakeholder access have full access to Azure Repos.

  • Repos must be enabled on your project. If the Repos hub and associated pages don't display, see Turn an Azure DevOps service on or off to reenable Repos.
  • To view code, you must be a member of an Azure DevOps project with Basic access or higher. If you aren't a project member, get added.
  • To view code, you must be a member of the Readers security group or have the corresponding permissions.
  • To contribute to code, you must be a member of the Contributors security group or have the corresponding permissions.
  • To view code, you must be a member of an Azure DevOps project with Basic access or higher. If you aren't a project member, get added.
  • To view code, you must be a member of the Readers security group or have the corresponding permissions.
  • To contribute to code, you must be a member of the Contributors security group or have the corresponding permissions.

Create a local Git repo for your project

Create a new local Git repo for your project by selecting Add to Source Control 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. You can also right-click your solution in Solution Explorer and choose Add Solution to Source Control.

Note

The Add to Source Control button in the status bar was added in Visual Studio 2017 (it was Publish in Visual Studio 2015 Update 2 and later) and will only appear when you have Git as your source control provider. If your code is already in a Git repo, you won't see the Add to Source Control button in the status bar, but the status of the current branch in your local repo instead.

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.

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 unpublished commits in your local branch. Selecting this opens the Synchronization view in Team Explorer.
  • Visual Studio Pending Changes Status Bar icon shows the number of uncommitted file changes. Selecting this opens the Changes view in Team Explorer.
  • Visual Studio Repo Status Bar icon shows the current Git repo. Selecting this opens 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.

Note

If you don't see any icons such as Visual Studio Unpublished Changes Status Bar icon or Visual Studio Pending Changes Status Bar icon, ensure that you have a project open that is part of a Git repo. If your project is brand new or not yet added to a repo, you can add it to one by selecting Add to Source Control on the status bar, or by right-clicking your solution in Solution Explorer and choosing Add Solution to Source Control.

Publish your code to Azure Repos

  1. Navigate to the Push view in Team Explorer by choosing the Visual Studio Unpublished Changes Status Bar icon icon in the status bar. You can also select Sync from the Home view in Team Explorer.

  2. In the Push view in Team Explorer, select the Publish Git Repo button under Push to Visual Studio Team Services.

    Publish your code from VS directly into Azure Repos

  3. Verify your email and select your account in the Team Services Domain drop-down.

  4. Enter your repository name and select Publish repository.

    Publish your VS project to a new Git repo in Azure Repos

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

  5. Your code is now in a Git repo in Azure Repos. You can view your code on the web by selecting See it on the web .

    View your Azure Repos/TFS Git repo on the Web

Review commit changes before publishing

  • To see what's changed in a commit, go to the Synchronization 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

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

    Adding work items to changes

    Also, you can include work items 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 Azure Repos.

Commit and push 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. Select the unpublished changes status bar icon Visual Studio Unpublished Changes Status Bar icon (or select Sync from the Home view in Team Explorer). Select Push to update your code in Azure DevOps Services/TFS.

    Push your changes

Pull changes from your team

Sync your local repo with changes from your team as they make updates.

  1. From the Synchronization view in Team Explorer, fetch the commits that your team has made. Double-click a commit to view its file changes.

    Choose Fetch to see any changes that your team has made

  2. Select Sync to merge the fetched commits into your local repo and then push any unpublished changes to Azure Repos.

    Choose Pull to get these commits locally

  3. The changes from your team are now in your local repo and visible in Visual Studio.

Troubleshooting

Q: Why is my sign-in page different than when I sign in to Visual Studio?

A: Your sign-in page depends on whether you used a Microsoft account or work account with Azure DevOps Services. So, sign in with the username and password that you used with Azure DevOps Services.

Q: Why doesn't Visual Studio launch when I click "Open in Visual Studio" on my project page?

A: This link requires Visual Studio 2013 or later. It doesn't launch earlier versions of Visual Studio.

Can I use the Git command prompt with Visual Studio?

A: Visual Studio's Team Explorer and the Git command line work great together. Changes to your repos made in either tool will be reflected in the other. Make sure to install the latest release of Git for Windows, which has tools to help you connect to your Azure DevOps Services/TFS repos.

See the Azure Repos Git tutorial and the command reference for additional help using Git from the command line.

Next steps

Set up a build for your code and learn more about using Git in the Azure Repos Git tutorial.