Update code with fetch and pull

VSTS | TFS 2015 & TFS 2017 | Visual Studio 2015 & 2017

Update the code in your local repo with the changes from other members of your team using the following commands:

  • fetch , which downloads the changes from your remote repo but does not apply them to your code.
  • merge , which applies changes taken from fetch to a branch on your local repo.
  • pull , which is a combined command that does a fetch and then a merge.

In this tutorial you learn how to:

  • Download changes with fetch
  • Update branches with merge
  • Fetch and merge with pull

Video Overview

If there is a merge conflict between a commit you haven't pushed yet and a commit you are merging or pulling, you'll need to resolve those conflicts before you finish updating your code.

Download changes with fetch

You download changes to your local branch from the remote through fetch. Fetch asks the remote repo for all commits and new branches that others have pushed but you don't have and downloads them into your repo, creating local branches as needed.

Fetch does not merge any changes into your local branches, it only downloads the new commits for your review.

Visual Studio uses the Sync view in Team Explorer to fetch changes. Changes downloaded by fetch are not applied until you Pull or Sync the changes.

Fetching changes in Visual Studio's Team Explorer Synchronization View

Update branches with merge

Apply changes downloaded through fetch using the merge command. Merge takes the commits retrieved from fetch and tries to add them to your local branch. The merge will keep the commit history of your local changes so that when you share your branch with push Git will know how others should merge your changes.

The challenge with merge is when a commit taken from fetch conflicts with an existing unpushed commit on your branch. Git is generally very smart about resolving merge conflicts automatically, but sometimes you must resolve merge conflicts manually and complete the merge with a new merge commit.

Team Explorer merges when you do a Pull or a Sync from the Changes view. Sync is a combined operation of pulling remote changes and then pushing local ones, synchronizing the commits on the local and remote branch.

Fetch and merge with pull

Pull does a fetch and then a merge to download the commits and update your local branch in one command instead of two. Use pull to quickly bring your branch up to date with the remote when you aren't worried about reviewing the changes before merging them into your own branch.

Open the Team Explorer and open the Sync view. Then click the Pull link under Incoming Commits to pull remote changes and merge them into your local branch. Pulling updates files in your open project, so make sure to commit your changes before pulling.

Pulling Changes with Visual Studio

Next steps