Get Started with Azure Repos and Visual Studio

**Azure Repos | Azure DevOps Server 2020 | Azure DevOps Server 2019 | TFS 2018 | TFS 2017 | TFS 2015 | VS 2017 **

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

Azure DevOps Server was formerly named Visual Studio Team Foundation Server (TFS).

If you don't have your code in an Azure Repos or Azure DevOps Server 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 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. Continue with the steps in this article to commit and share your work.

  1. In Team Explorer, select Connect to open the Connect page, and then choose Manage Connections > Connect to Project.

    Cloning Azure DevOps Server Git repositories in Visual Studio

  2. In Connect to a Project, select the repo you want to clone and select Clone. If you don't see your repo, select Add Azure DevOps Server to add a server that hosts a repo. You can filter the list to find your repo.

    Cloning a Git Repository from a connected organization in Azure Repos

    Note

    Project URLs have changed with the release of Azure DevOps Services and now have the format dev.azure.com/{your organization}/{your project}, but you can still use the existing visualstudio.com format. For more information, see VSTS is now Azure DevOps Services.

  3. Verify the location of the cloned repo on your computer and select Clone.

Commit your work

Git branches isolate your changes from other work 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, select the Home button and choose Branches.

    Screenshot showing Branches in Team Explorer.

  2. Right-click the master branch and choose New Local Branch From.

    Creating a Local Branch off the Master branch in Visual Studio

  3. Enter a descriptive branch name for your work to remind you and others what kind of work is in the branch. Select Create Branch.

    Enter a descriptive branch name and select Create Branch.

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

  5. When you're satisfied with the changes, save them in Git using a commit. Open the Changes view from Team Explorer by selecting the Home button and choosing Changes.

    Screenshot that shows opening the Changes view.

  6. Enter a message that describes the commit, and select Commit All.

    Commit All

    Note

    If you have multiple files and you don't want to commit them all, you can right-click each file and choose Stage. When you have staged all the files you would like to commit, select Commit Staged. Commit Staged replaces Commit All when you manually stage your changes before the commit.

    Stage files

Share your changes

When you're ready to share your changes with the team, 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. A pull request lets others know you'd like to have the changes reviewed. After approval, a pull request adds your changes to the master branch of the code.

  1. In Team Explorer, select Home and then choose Sync to open Synchronization.

    Synchronization

    You can also go to the Synchronization view from Changes by choosing Sync immediately after making a commit.

    Choose Sync immediately after making a commit.

  2. Select Push to share your commit with the remote repository.

    Push

    If this push is your first to the repository, you'll see the following message: The current branch does not track a remote branch. Push your changes to a new branch on the origin remote and set the upstream branch. Select Push to push your changes to a new branch on the remote repository and set the upstream branch. The next time you push changes, you'll see the list of commits.

  3. Create a pull request so that others can review your changes. Open Pull Requests in Team Explorer by selecting Home and choosing Pull Requests.

    Pull Requests

  4. In Pull Requests, you can view pull requests opened by you, assigned to you, and you can create new pull requests. Select New Pull Request to open a web browser where you can create the new pull request in the Azure Repos web portal.

    Select New Pull Request.

  5. Verify your branches. In this example, we want to merge the commits from the ReadMeFix branch into the master branch. Enter a title and optional description, specify any reviewers, optionally associate any work items, and then select Create.

    Create a Pull Request in the web portal

    For more information on pull requests, see the pull request tutorial.

Sync with others

To keep your code up to date, 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. Pulling often makes sure that your feature branches from your main branch are using the latest version of the code.

  1. In Team Explorer, select Home and choose Sync to open Synchronization.

    Synchronization with others.

  2. You can download the latest changes to your branch using the Pull link. There are two Pull links, one near the top and one in the Incoming Commits section. You can use either because they both do the same thing.

    Download changes to your local repo