Get Started with Git and Azure DevOps Services

Azure Repos | Azure DevOps Server 2019 | TFS 2018 | TFS 2017 | TFS 2015

This guide covers the basics so you can get up and running using Git with code already in Azure DevOps Services or Team Foundation Server (TFS). Explore our full tutorial for more information on how to use Git from Visual Studio or the command line.

If you don't have your code in an Azure DevOps Services or TFS Git repo, visit our Visual Studio or command line getting started articles to learn how to create a local repo for your code and push it to Azure Repos.

Get your code

To get a copy of the source code, you will clone a Git repository. Cloning creates both a copy of the source code for you to work with and all the version control information so Git can manage the source code.

If you don't have a Git repository yet, you can create one using your own code and continue with the steps to commit and share your work.

  1. In Team Explorer, open up the Connect page by choosing Projects and My Teams then Manage Connections

    Cloning Git repositories in Visual Studio

  2. Choose Connect, select your organization, choose the projects you want to work on, then click Connect.

  3. Right click on the project and click Clone.... Then enter a local folder on your drive to store the downloaded code.

    Cloning a Git Repository from a connected organization in Azure DevOps

Commit your work

Git branches isolate your changes from other work being done in the project. The recommended Git workflow uses a new branch for every feature or fix you work on. You make commits in your local Git repository to save your changes on that branch.

  1. In Team Explorer, click the drop down and choose Branches. Right click the master branch and choose New Local Branch From...

    Creating a Local Branch off the Master branch in Visual Studio

    Choose a descriptive branch name for your work to remind you and others what kind of work is in the branch.

  2. Make changes to your files in the cloned repo. From the Team Explorer Home view, you can open up Visual Studio solutions in the repo or browse the repo contents using the Show Folder View link. Git keeps track of changes made to your code both inside and outside of Visual Studio.

  3. When you are satisfied with the changes, save them in Git using a commit. Open up the Changes view from Team Explorer. Stage the changes to add to your next commit by right-clicking the files and selecting Stage, add a message describing the commit, then select Commit Staged.

    Committing changes to a Git branch in Visual Studio

Share your changes

When you are ready to share your changes with the team, you push those changes so that others can reach them. You can only push changes after you add commits to a branch.

Once you push the changes, you can create a pull request to let others know you'd like to have the changes reviewed and added to the master branch of the code.

  1. Open up the Synchronization view in Team Explorer. You can see the outgoing commits and share them by clicking Push if you are working with a branch that is already shared, or Publish if you are working with a newly created local branch.

    Sharing Code in Git using Push in Visual Studio

  2. Create a pull request so that others can review your changes. Open Pull Requests in Team Explorer, and click New Pull Request. Verify the remote branch to merge the changes into, such as my-feature.

    Create a Pull Request in Visual Studio

  3. You can review comments made in your pull request in a web browser on the Azure Repos pull request page. Once all changes are approved by the team, you complete the pull request through the web browser.

Sync with others

To get changes from others and keep your code up to date, you pull commits made by others and merge them into your branch. Git is very good about merging multiple changes even in the same file, but sometimes you might have to resolve a merge conflict. It's a good idea to pull your branches regularly to keep them up to date with the changes from others. This makes sure that your feature branches from your main branch are using the latest version of the code.

  1. Open up the Sync view in Team Explorer. You can download the latest changes to the branch you are on using the "Pull" link.

    Using Pull to download changes in Git in Visual Studio