Azure DevOps Services | Azure DevOps Server 2020 | Azure DevOps Server 2019 | TFS 2018

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

Share your Visual Studio solution with others by hosting your code in an Azure Repos Git repository. Y'all can apply Visual Studio to manage Azure Repos Git repositories or GitHub repositories. This commodity provides procedures for the following tasks:

  • Add a project or solution to a local Git repository
  • Publish your code to an Azure Repos Git repository or GitHub repository
  • Review your code changes earlier publishing
  • Link work items to your commits
  • Commit and push updates
  • Pull changes from the primary co-operative of your repository

To clone a GitHub repository, get the clone URL equally described in Cloning a repository.

For an overview of the Git workflow, see Azure Repos Git tutorial.

Prerequisites

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

  • To view code in private projects, you must be a member of an Azure DevOps project with Basic access level or higher. For public projects, everyone can view the code.

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

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

  • To clone or contribute to code for a private project, you must be a member of the Contributors security group or have the corresponding permissions prepare. For public projects, anyone can clone and contribute code. To acquire more, encounter What is a public projection?

    Note

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

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

  • To view code, you must be a fellow member of the Azure DevOps project with Bones access or higher. If you lot aren't a project member, get added.

  • To clone or contribute to code, yous must be a member of the Contributors security grouping, or have the corresponding permissions, in the projection you want to change.

  • To view code, you must exist a fellow member of an Azure DevOps project with Basic admission or higher. If you aren't a project member, get added.

  • To clone or contribute to code, yous must be a fellow member of the Contributors security group or have the corresponding permissions.

To learn more about permissions and access, run into Default Git repository and branch permissions and About access levels.

Note

Visual Studio 2019 version xvi.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 commodity under the Visual Studio 2019 tab provide information for using the Git experience equally well as Squad Explorer. To acquire more, see Side-by-side comparison of Git and Team Explorer.

Add a project or solution to a new local Git repository

The commencement footstep to sharing your Visual Studio solution with others using Git is to create a local Git repo for your code. If it'southward your offset time using Visual Studio to connect to Azure Repos, run into Connect to a project from Visual Studio for details.

  • Visual Studio 2019
  • Visual Studio 2017
  • Visual Studio 2015.ii
  • Visual Studio 2013
  • Git Command Line
  1. Create a new local Git repo for your Visual Studio solution, by correct-clicking the solution proper name in Solution Explorer, and so selecting Create Git Repository. Or, choose Add to Source Control on the status bar in the lower correct-mitt corner of Visual Studio, and then select Git. If you don't see these options, then your code is already in a Git repo.

    Screenshot of the 'Create Git repository' option in the Solution Explorer context menu in Visual Studio 2019.

    Or, cull Git > Create Git Repository from the card bar to launch the Create a Git repository window. If you don't see this choice, and so your lawmaking is already in a Git repo.

    Screenshot of the 'Create Git Repository' option in the Git menu from the menu bar of Visual Studio 2019.

  2. This step simply applies to the Visual Studio Git version control experience: in the Create a Git repository window, choose Local only, verify the local path is correct, and so choose Create.

    Screenshot of the 'Create a Git repository' window with the 'Local only' option selected in Visual Studio 2019.

    Team Explorer doesn't launch the Create a Git repository window, and assumes you want a local Git repo.

Y'all've now created a local Git repo in the Visual Studio solution folder and committed your code into that repo. Your local Git repo contains both your Visual Studio solution and Git resources.

Screenshot of the Git folder, Git ignore file, and Git attributes file in Windows file explorer.

Publish your lawmaking

You lot can share your work with others past publishing your local Git repo to an Azure Repos Git repo.

  • Visual Studio 2019
  • Visual Studio 2017
  • Visual Studio 2015.2
  • Visual Studio 2013
  • Git Command Line

Visual Studio 2019 version xvi.viii and later versions provides a Git version control feel while maintaining the Team Explorer Git user interface. To utilize Team Explorer, uncheck Tools > Options > Preview Features > New Git user feel from the card bar. You can practice Git features from either interface interchangeably. Below, we provide a side-by-side comparison for publishing your code.

Note

One advantage of connecting to a project through Squad Explorer is you gain access to the Work Items hub. For an overview of Squad Explorer features, come across Navigate in Visual Studio Team Explorer.

  1. Connect to an Azure DevOps repo by right-clicking the solution name in Solution Explorer, and then selecting Push to Git service to launch the Create a Git repository window.

Screenshot of the 'Push to Git service' menu option in the Git menu on the menu bar in Visual Studio 2019.

Or, choose Git > Push to Git service from the menu bar to launch the Create a Git repository window.

Screenshot of the 'Push to Git service' option in the in Visual Studio 2019 context menu.

  1. Open a browser and navigate to your Azure DevOps projection by using a URL in the class of https://dev.azure.com/<OrganizationName>/<ProjectName>. If you don't accept a projection however, create one.

  2. In your Azure DevOps project, Create an empty Git repo without a README file. Copy the clone URL from the Clone Repository popup.

Screenshot of the 'Clone Repository' popup from the Azure DevOps project site.

  1. In the Create a Git repository window, choose Existing remote and enter the repo clone URL from the previous step, and then choose Push button. For more data on how to create a new Azure DevOps repo, see Create a new Git repo in your project.

Screenshot of the 'Create a Git repository' window, with the URL of an empty Azure repo, in Visual Studio 2019.

  1. The Git Changes window shows a confirmation message that your code is now in an Azure DevOps repo.

Screenshot of the 'Git Changes' window, with a confirmation message that your code is in 'Azure DevOps' repo, in Visual Studio 2019.

Visual Studio Team Explorer
  1. In the Push button to Azure Dev Ops Services section of the Synchronization view in Team Explorer, select the Publish Git Repo button.

Screenshot of the 'Push' view of 'Team Explorer' in Visual Studio 2019.

  1. Choose your Azure DevOps business relationship, organization, and repo name, and then select Publish Repository.

Screenshot of the Azure DevOps account, organization, and repo name options and the 'Publish Repository' button in the 'Synchronization' view of 'Team Explorer' in Visual Studio 2019.

This step creates a new projection in your Azure DevOps account with the aforementioned name that you selected for the repo. To create the repo in an existing projection, select Advanced next to the Repository proper noun, then choose a project.
  1. Your code is now in a Azure Repos Git repository. You lot can view your code on the web by selecting Encounter it on the web.

Screenshot of the 'See it on the web' link in the 'Home' view of 'Team Explorer' in Visual Studio 2019.

Review commit changes

It's expert practice to review the code changes in your commit before publishing. Visual Studio provides a diff view that helps you see all the changes you've fabricated since the previous commit.

  • Visual Studio 2019
  • Visual Studio 2017
  • Visual Studio 2015.2
  • Visual Studio 2013
  • Git Control Line
  1. To meet what's changed in a commit, open the Git Repository window by choosing Git > Manage Branches from the menu bar.

Screenshot of in Visual Studio 2019.

  1. In the Git Repository window, select your branch, correct-click the commit, and and so choose View Commit Details to open the Commit window.

Screenshot of the 'View Commit Details' menu option for a commit in the 'Git Repository' window in Visual Studio 2019.

  1. In the Commit window, you can right-click on any file and select Compare with Previous to view the file changes made by the commit.

Screenshot of the 'Compare with Previous' option in the Commit pane in Visual Studio 2019.

Visual Studio Team Explorer
  1. To see what's changed in a commit, go to the Synchronization page in Team Explorer, correct-click on any commit, and and so cull View Commit Details to open up the Git Details window.

Screenshot of a commit in the Synchronization view of Team Explorer in Visual Studio 2019.

  1. In the Commit Details window, you tin can right-click on any file and select Compare with Previous to view the file changes made past the commit.

Screenshot of the 'Compare with Previous' option in the 'Commit Details' window in Visual Studio 2019.

As you develop your software, you tin can capture which commits back up the completion of work items similar Azure DevOps tasks or bug fixes. The audit trail of piece of work items linked to commits lets your team understand how tasks and bugs were resolved.

Annotation

The #ID syntax is supported when you lot connect to an Azure Repos Git repository. If you connect to a GitHub repository, you can still link to work items, but must use the #ABID syntax, and have previously set up an Azure Boards-GitHub connectedness.

  • Visual Studio 2019
  • Visual Studio 2017
  • Visual Studio 2015.two
  • Visual Studio 2013
  • Git Command Line

Visual Studio Git

Yous can link work items to commits past adding #ID into the commit bulletin. For example, the commit bulletin "Fix issues #12 in the reporting tools" would link piece of work item 12 to the commit when the commit is pushed to Azure Repos.

Screenshot of a work item linked to a commit in the 'Git Changes' window in Visual Studio 2019.

Visual Studio Team Explorer

Yous can include piece of work items in your commits through Related Work Items in the Changes view of Squad Explorer.

Screenshot of a work item linked to a commit in the Changes view of Team Explorer in Visual Studio 2019.

Y'all can also link work items to commits past adding #ID into the commit message. For case, the commit message "Fix bug #12 in the reporting tools" would link piece of work detail 12 to the commit when the commit is pushed to Azure Repos.

Push commit changes

  • Visual Studio 2019
  • Visual Studio 2017
  • Visual Studio 2015.two
  • Visual Studio 2013
  • Git Control Line

As you write your lawmaking, your changes are automatically tracked by Visual Studio. When you're satisfied with your changes, you can save them in Git using a commit, and so push your commit to Azure Repos.

  1. In the Git Changes window, enter a message that describes the changes, and then choose Commit All. Commit All commits unstaged changes and skips the staging surface area. Yous can cull to stage all files before committing by selecting the stage all + (plus) push at the peak of the Changes section of the Git Changes window.

Screenshot of the 'Commit All' button in the 'Git Changes' window in Visual Studio 2019.

  1. To push your commit to Azure Repos, select the upward-arrow button button.

Screenshot of the up-arrow push button in the 'Git Changes' window of Visual Studio 2019.

Or, you can push button your commit from the Git Repository window. To open up the Git Repository window, select the outgoing / incoming link in the Git Changes window.

Screenshot of the 'outgoing / incoming' link in the 'Git Changes' window, and the Push link in the 'Git Repository' window of Visual Studio 2019.

Or, you can choose Git > Push from the menu bar.

Screenshot of the Push option from the Git menu in Visual Studio 2019.

Visual Studio Team Explorer
  1. Open the Changes view of Squad Explorer past selecting the Abode button and choosing Changes. Or, select the pending changes icon Visual Studio Pending Changes Status Bar icon on the status bar.

Screenshot of the Changes option in Team Explorer in Visual Studio 2019.

  1. In the Git Changes window, enter a message that describes the changes, and then cull Commit All. Commit All commits unstaged changes and skips the staging area. Y'all can choose to stage all files before committing by selecting the stage all + (plus) push at the top of the Changes department in the Git Changes window.

Screenshot of the 'Screenshot of commit message text and 'Commit All' button in Visual Studio 2019.

  1. To button one or more commits to Azure Repos, select Dwelling and and so choose Sync to open the Synchronization view in Team Explorer. Or, select the unpublished changes condition bar icon (Visual Studio unpublished changes status bar icon on the status bar.

Screenshot of the Sync option in Team Explorer in Visual Studio 2019.

  1. In the Synchronization view, cull Button to upload your commit to the remote repo. If this is your commencement push to the repo, you'll see the message: The current branch does not track a remote branch..., which lets yous know that your commit was pushed to a new co-operative on the remote repo and that future commits pushed from the current branch will be uploaded to that remote branch.

Screenshot of the Push link in the Synchronization view of Team Explorer in Visual Studio 2019.

Pull changes

  • Visual Studio 2019
  • Visual Studio 2017
  • Visual Studio 2015.2
  • Visual Studio 2013
  • Git Control Line

You lot can keep your local branches in sync with their remote counterparts by pulling commits created past others. While you're working on your feature branch, information technology's a good idea to periodically switch to your main co-operative and pull new commits to keep it current with the remote main branch.

Note

Fetch and Pull links can be institute in different views and in the Git menu on the card bar. Those links all do the aforementioned thing—fetch or pull from the remote repo to the electric current branch of the local repo.

  1. In the Git Changes window, you tin cheque for the latest commits on the remote co-operative past using the down-arrow fetch link, and so selecting the outgoing / incoming link to open up the Git Repository window. Fetch downloads remote commits that aren't in your local co-operative, but won't merge them into your local branch. Fetched commits show up in the Incoming Commits section of the Git Repository window. You can double-click a fetched commit to view its file changes.

Screenshot of the Fetch, Pull, Push and Sync buttons in the 'Git Changes' window of Visual Studio 2019.

  1. Choose Pull to merge the fetched remote commits into your local repo. Pull performs a fetch and then merges the downloaded commits into your local branch.
Visual Studio Team Explorer
  1. In Squad Explorer, select Domicile and choose Sync to open the Synchronization view.

Screenshot of the Sync option in 'Team Explorer' in Visual Studio 2019.

  1. In the Synchronization view, you can preview the latest changes on the remote branch by using the Fetch link. Fetch downloads remote commits that aren't in your local co-operative, simply doesn't merge them. Fetched commits show upwards in the Incoming Commits department of the Synchronization view. You can double-click a commit to view its file changes.

Screenshot of the Pull link in the Synchronization view of Team Explorer in Visual Studio 2019.

  1. Cull Pull to merge the fetched remote commits into your local repo. Pull performs a fetch and and then merges the downloaded commits into your local co-operative.

FAQs

Q: Why does the sign-in folio differ between the spider web portal and Visual Studio?

A: Your sign-in folio depends on whether you used a Microsoft account or a work business relationship with Azure DevOps. Always sign in with the username and countersign that you use for Azure DevOps.

Q: Tin I employ the Git command prompt with Visual Studio?

A: Visual Studio's Squad Explorer and the Git command-line work keen together. Changes to your repos made in either tool volition exist 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 assist using Git from the control line.

Next steps

  • New to Git repos? Learn more