Skip to content

Git rebase conflict resolution

Git rebase conflict resolution is the process of handling incompatible changes that arise when rewriting commit history using git rebase. This typically occurs when integrating upstream changes into a feature branch or updating local history with remote changes.

Workflow

When a conflict is detected during a rebase operation, Git will pause the process and wait for the user to resolve the differences. The standard resolution workflow involves the following steps:

  1. Identify and resolve conflicts: Edit the conflicting files to fix the differences.
  2. Stage the resolution: Use git add . or git add <conflicted_files> to mark the conflicts as resolved.
  3. Continue the rebase: Run git rebase --continue to proceed with the remaining commits^[600-developer-tools-git-git-rebase.md:40-43].

This cycle repeats for every commit in the series that encounters a conflict.

Without Branches (Single Branch)

In scenarios where multiple developers are working on the same branch (without feature branches), rebase is used to move local commits to the tip of the remote branch.^[600-developer-tools-git-git-rebase.md:45-46]

The workflow to resolve conflicts in this context is:

  1. Fetch the latest changes (git fetch).
  2. Start the rebase (git rebase).
  3. Resolve conflicts and add files (git add).
  4. Continue the rebase (git rebase --continue).
  5. Push the updated history^[600-developer-tools-git-git-rebase.md:48-51].

A streamlined workflow combines the fetch and rebase steps using git pull --rebase, after which the standard resolution and push steps apply^[600-developer-tools-git-git-rebase.md:56-60].

Configuration

To streamline the workflow, Git can be configured to use rebase by default during a pull operation.

  • Per-branch: git config branch.master.rebase true sets the master branch to rebase by default^[600-developer-tools-git-git-rebase.md:62].
  • Global: git config --global pull.rebase true applies rebase to all branches by default^[600-developer-tools-git-git-rebase.md:75].
  • Automatic setup: git config --global branch.autoSetupRebase always ensures new branches automatically favor rebase^[600-developer-tools-git-git-rebase.md:76].
  • [[Git merge]]
  • [[Version control]]

Sources

  • 600-developer-tools-git-git-rebase.md