Update lawmaking with fetch, merge, and pull

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

Visual Studio 2022 | Visual Studio 2019 | Visual Studio 2017 | Visual Studio 2015

When at that place are several contributors to a projection, keep your local Git repo updated by downloading and integrating work that others uploaded to the projection's remote repo. These Git commands update your local repo:

  • Git fetch downloads whatsoever new commits that others uploaded to the remote repo. The remote-tracking branches in local repo enshroud are updated—local branches remain unchanged.
  • Git merge integrates commits from one or more source branches into a target branch.
  • Git rebase integrates commits from a source co-operative into a target co-operative, but uses a different strategy than Git merge.
  • Git pull performs a fetch and then a merge or rebase to integrate fetched commits into your electric current local branch.

Visual Studio uses a subset of those Git commands when you lot synchronize your local repo with a remote repo.

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

This article provides procedures for the following tasks:

  • Download changes with fetch
  • Update branches with merge or rebase
  • Download changes and update branches with pull

Download changes with fetch

Git fetch downloads remote branch commits and referenced file objects that don't exist in your local repo and updates the remote-tracking branches in local repo enshroud. Remote-tracking branches are locally cached read-merely copies of remote branches and aren't your local branches. Git fetch doesn't update your local branches. For example, if a remote repo designated by origin has a bugfix3 branch, Git fetch volition update the remote-tracking co-operative named origin/bugfix3 and not your local bugfix3 branch. You can use remote-tracking branches to:

  • Compare a remote-tracking co-operative with a local branch to review fetched changes.
  • Merge a remote-tracking branch into a local branch.
  • Create a new local branch from a remote-tracking branch.
  • Visual Studio 2019
  • Visual Studio 2017
  • Git Command Line

Visual Studio 2019 version xvi.8 and later versions provides a Git version control experience while maintaining the Squad Explorer Git user interface. To utilize Team Explorer, uncheck Tools > Options > Preview Features > New Git user feel from the menu bar. You can employ Git features from either interface interchangeably. Below, nosotros provide a side-by-side comparison of how to perform a Git fetch.

  1. In the Git Changes window, choose Fetch. Then select outgoing/incoming to open up the Git Repository window.

Screenshot of the Fetch buttons and Incoming link in the Git Changes window of Visual Studio 2019.

You can also choose Fetch from the Git carte du jour.

Screenshot of the Fetch option in the Git menu in Visual Studio 2019.

  1. In the Git Repository window, fetched commits appear in the Incoming department. Select a fetched commit to see the list of inverse files in that commit. Select a changed file to see a diff view of changed content.

Screenshot of the Git Repository menu in Visual Studio 2019.

Visual Studio Team Explorer
  1. In Team Explorer, select Dwelling and so choose Sync to open the Synchronization view.

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

  1. In the Synchronization view, choose Fetch. Both Fetch buttons do the same thing. When downloaded, fetched commits will appear in the Incoming Commits section.

Screenshot of the Fetch button in the Synchronization view of Team Explorer in Visual Studio 2019.

  1. In the Incoming Commits department, correct-click a commit and and so choose View Commit Details to see the changed files.

Screenshot of the context menu for incoming commits in the Synchronization view of Team Explorer in Visual Studio 2019.

  1. In the Commit Details window, the changed files are listed in the Changes section.

Screenshot of the Commit Details window within Visual Studio 2019.

Double-click a changed file to open a diff view of changed content.

Screenshot of a file diff window in Visual Studio 2019.

Tip

Fetch won't delete remote-tracking branches in your local repo cache that no longer have a remote analogue. To configure Visual Studio to prune stale remote-tracking branches during a Fetch:

  • Select Tools > Options > Source Control > Git Global Settings.
  • Set the Prune remote branches during fetch option to True.

After a Git fetch, yous can compare a local branch with its corresponding remote-tracking branch to run into what inverse on the remote branch. If you determine to update your current local branch with fetched changes, yous can perform a Git merge or rebase. Or, you lot tin can run Git pull, which combines a Git fetch with a Git merge or rebase. Both Git merge and Git rebase update a target branch by applying commits from a source branch onto it. Nevertheless, Git merge and Git rebase employ different strategies. For more than data, run across Update branches with merge or rebase and When to rebase vs. merge.

Update branches with merge or rebase

Git merge and Git rebase integrate commits from a source branch into your current local branch (target co-operative). Git merge performs either a fast-forward or a no-fast-frontward merge. The no-fast-forrad merge is also known as a three-way merge or truthful merge. Git rebase is another type of merge. These merge types are shown in the following diagram.

Diagram showing the before and after commits when using merge and rebase.

Git merge and Git rebase are extensively used in the Git workflow. When working on a local characteristic or bugfix co-operative, it'southward common practice to:

  1. Keep your local main branch current with its remote counterpart by periodically pulling to fetch and merge remote commits.
  2. Integrate local main co-operative updates into your local feature branch using a rebase or merge.
  3. Back up your piece of work on the local feature co-operative past pushing it to the corresponding remote branch.
  4. On characteristic completion, create a pull asking to merge your remote feature branch into the remote main branch.

This approach helps you:

  • Stay aware of contempo work by others that might touch your work.
  • Promptly resolve whatsoever conflicts between your piece of work and that of others.
  • Use your new feature on tiptop of up-to-appointment project content.
  • Get a pull asking review of your work.

Merge

For Git merge, if the tip of the target co-operative exists within the source branch, the default merge blazon will be a fast-forrad merge. Otherwise, the default merge type volition be a no-fast-forward merge.

A fast-forwards Git merge tin can never have a merge disharmonize considering Git won't apply a fast-forwards merge if the tip of the target co-operative has diverged from the source co-operative. By default, Git uses a fast-forrad merge whenever possible. For instance, Git will apply a fast-forwards merge on a local co-operative that y'all only update by pulling from its remote counterpart co-operative.

A no-fast-forward Git merge generates a new target branch "merge commit" that integrates source branch changes with target branch changes. The applicable changes are those made later on the concluding commit that'southward common to both branches. In the preceding diagram, commit C is the concluding mutual commit in both branches. If any source branch modify conflicts with any target co-operative change, and so Git will prompt you to resolve the merge conflict. The merge commit (L) contains the integrated source co-operative and target branch changes. The source and target branch tips (K and Eastward) are the parents of the merge commit. In your branch's commit history, a merge commit is a useful marker for a merge operation, and clearly shows which branches were merged.

Git merge only modifies the target co-operative—the source co-operative remains unchanged. When y'all see one or more merge conflicts, yous must resolve them to complete the merge. Or, y'all can cancel the merge functioning and return the target branch to its prior state.

For more information on merge options and strategies, run across the Git reference manual and Git merge strategies.

Tip

If the source branch is a remote-tracking branch, ensure that co-operative is upwardly-to-appointment by running a Git fetch before the merge.

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

Visual Studio 2019 version xvi.eight and later versions provides a Git version control experience while maintaining the Team Explorer Git user interface. To utilize Team Explorer, uncheck Tools > Options > Preview Features > New Git user experience from the menu bar. You tin can utilise Git features from either interface interchangeably. Below, nosotros provide a side-past-side comparison of how to perform a Git merge.

  1. Cull Git > Manage Branches from the menu bar to open the Git Repository window.

Screenshot of the Manage Branches option in the Git menu of Visual Studio 2019.

  1. In the Git Repository window, right-click the target co-operative and select Checkout.

Screenshot of the Checkout option in the Git Repository window of Visual Studio 2019.

  1. Correct-click the source branch, and select Merge <source-branch> into <target-branch>.

Screenshot of the Merge option in the Git Repository window of Visual Studio 2019.

  1. Visual Studio will display a confirmation message after a successful merge.

Screenshot of the merge confirmation message in the Git Repository window of Visual Studio 2019.

If the merge is halted due to merge conflicts, Visual Studio will notify you. You tin can either resolve the conflicts, or cancel the merge and return to the pre-merge state.

Screenshot of the merge conflict message in the Git Repository window of Visual Studio 2019.

Visual Studio Team Explorer
  1. In Squad Explorer, select Home and choose Branches.

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

  1. In the Branches view, correct-click the target co-operative and select Checkout.

Screenshot of the Checkout option in the Branches view of Team Explorer in Visual Studio 2019.

  1. Right-click the source branch, and select Merge From.

Screenshot of the Merge From option in the Branches view of Team Explorer in Visual Studio 2019.

  1. Verify the merge options then click Merge.

Screenshot of the merge details in the Branches view of Team Explorer in Visual Studio 2019.

  1. Visual Studio volition display a confirmation message after a successful merge.

Screenshot of the merge confirmation message in the Branches view of Team Explorer in Visual Studio 2019.

If there are conflicts during the merge, Visual Studio volition notify you. You can either resolve the conflicts, or cancel the merge and render to the pre-merge country.

Screenshot of the merge conflict message in the Branches view of Team Explorer in Visual Studio 2019.

Rebase

Git rebase resequences the commit history of the target branch so that information technology contains all source co-operative commits, followed past all target branch commits since the last common commit. Another mode to view it is that a Git rebase replays the changes in your target branch on top of the source co-operative history. If any source branch change conflicts with any target co-operative change, then Git will prompt you to resolve the merge conflict. Git rebase doesn't create a merge commit. Notably, Git rebase changes the sequence of the existing target co-operative commits, which isn't the case for the other merge strategies. In the preceding diagram, commit Grand' contains the same changes as K, simply has a new commit ID because information technology links back to commit E instead of C.

Git rebase only modifies the target branch—the source branch remains unchanged. When you encounter one or more merge conflicts, yous must resolve them to complete the rebase. Or, yous can cancel the rebase performance and return the target branch to its prior state.

If you're the only person working on your characteristic or bugfix co-operative, consider using Git rebase to integrate new main branch commits into it. Otherwise, apply Git merge. For more information on Git rebase and when to apply it, see Utilise changes with rebase and Rebase vs merge.

Tip

If the source branch is a remote-tracking branch, ensure that branch is up-to-date by running a Git fetch before the rebase.

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

Visual Studio 2019 version 16.8 and later versions provides a Git version control experience while maintaining the Squad Explorer Git user interface. To use Team Explorer, uncheck Tools > Options > Preview Features > New Git user experience from the menu bar. Y'all can utilize Git features from either interface interchangeably. Below, we provide a side-by-side comparison of how to perform a Git rebase.

  1. Choose Git > Manage Branches to open up the Git Repository window.

Screenshot of the Manage Branches option in the Git menu of Visual Studio 2019.

  1. In the Git Repository window, right-click the target branch and select Checkout.

Screenshot of the Checkout option in the branch context menu in the Git Repository window of Visual Studio 2019.

  1. Correct-click the source co-operative, and select Rebase <target-branch> onto <source-branch>.

Screenshot of the Rebase option in the branch context menu in the Git Repository window of Visual Studio 2019.

  1. Visual Studio volition display a confirmation message after a successful rebase.

Screenshot of the rebase confirmation message in the Git Repository window of Visual Studio 2019.

If the rebase is halted due to merge conflicts, Visual Studio will notify you lot. You can either resolve the conflicts, or cancel the rebase and return to the pre-rebase state.

Screenshot of the rebase conflict message in the Git Repository window of Visual Studio 2019.

Visual Studio Team Explorer
  1. In Squad Explorer, select Habitation and choose Branches.

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

  1. In the Branches view, right-click the target branch and select Checkout.

Screenshot of the Checkout option in the Branches view of Team Explorer in Visual Studio 2019.

  1. Right-click the source branch, and select Rebase Onto.

Screenshot of the Rebase Onto option in the Branches view of Team Explorer in Visual Studio 2019.

  1. Verify the rebase options and and so click Rebase.

Screenshot of the rebase details in the Branches view of Team Explorer in Visual Studio 2019.

  1. Visual Studio volition display a confirmation bulletin later a successful rebase.

Screenshot of the rebase confirmation message in the Branches view of Team Explorer in Visual Studio 2019.

If in that location are conflicts during the rebase, Visual Studio will notify you. You lot tin can either resolve the conflicts, or abolish the rebase and render to the pre-rebase state.

Screenshot of the rebase conflict message in the Branches view of Team Explorer in Visual Studio 2019.

Download changes and update branches with pull

Past default, Git pull combines a Git fetch and a Git merge to update your current local branch from its remote counterpart. Optionally, Git pull can perform a Git rebase instead of a Git merge.

Unlike Git fetch, Git pull will update your current local branch immediately after downloading new commits from the remote repo. Utilize Git pull when you lot know you lot want to update your current local branch correct after a Git fetch.

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

Visual Studio 2019 version xvi.eight and after versions provides a Git version control experience while maintaining the Team Explorer Git user interface. To utilize Team Explorer, uncheck Tools > Options > Preview Features > New Git user experience from the menu bar. Y'all can use Git features from either interface interchangeably. Below, nosotros provide a side-by-side comparison of how to perform a Git pull.

Tip

To configure Visual Studio to rebase instead of merge when you Pull:

  1. From the Git menu, become to Tools > Options > Source Control > Git Global Settings.
  2. Set up the Rebase local co-operative when pulling option to Truthful.
  1. In the Git Changes window, choose Pull.

Screenshot of the Pull button in the Git Changes window of Visual Studio 2019.

You tin can also choose Pull from the Git menu.

Screenshot of the Pull option in the Git menu in Visual Studio 2019.

  1. A confirmation message displays when the pull operation completes.

Screenshot of the pull confirmation message in the Git Changes window in Visual Studio 2019.

If in that location are conflicts during the merge portion of the pull operation, Visual Studio will notify y'all. You lot tin either resolve the conflicts, or cancel the merge and render to the pre-merge land.

Screenshot of the pull conflict message in the Git Changes window in Visual Studio 2019.

Visual Studio Squad Explorer
  1. In Team Explorer, select Home 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, cull Pull. Both Pull buttons do the same thing.

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

  1. Visual Studio will display a confirmation message when the pull operation completes.

Screenshot of the pull confirmation message in the Synchronization view of Team Explorer in Visual Studio 2019.

If there are conflicts during the merge portion of the pull operation, Visual Studio will notify you. Y'all tin can either resolve the conflicts, or cancel the merge and render to the pre-merge land.

Screenshot of the pull conflict message in the Synchronization view of Team Explorer in Visual Studio 2019.

Side by side steps

  • New to Git repos? Learn more