Skip to content

Rebase conflict resolution

Rebase conflict resolution is the process required when a git rebase operation encounters conflicting changes between the branch being moved (the topic branch) and the new base commit.^[600-developer__tools__git__git-rebase.md]

Resolution Workflow

When a conflict arises during a rebase operation, the standard resolution sequence involves identifying the conflicting files, editing them to resolve the differences, and explicitly instructing Git to proceed with the operation^[600-developer__tools__git__git-rebase.md].

  1. Identify Conflict: The rebase process pauses and indicates which files have conflicts^[600-developer__tools__git__git-rebase.md].
  2. Resolve Conflict: Manually edit the conflicting files to fix the code inconsistencies^[600-developer__tools__git__git-rebase.md].
  3. Stage Changes: Run git add <conflicted_files> to mark the conflicts as resolved^[600-developer__tools__git__git-rebase.md].
  4. Continue: Execute git rebase --continue to apply the remaining commits^[600-developer__tools__git__git__git-rebase.md].

This workflow is commonly encountered when synchronizing a local development branch with an updated master branch or when pulling updates from a remote repository^[600-developer__tools__git__git-rebase.md].

Rebase vs. Merge Workflow

In a typical feature branch workflow, rebase is used to apply changes onto the latest master before merging^[600-developer__tools__git__git-rebase.md].

  • Standard Rebase: After fetching the latest master, one would checkout the feature branch (e.g., issue) and run git rebase master^[600-developer__tools__git__git-rebase.md].
  • Post-Rebase Merge: Once the rebase is complete and conflicts are resolved, the branch is checked out to master and merged using git merge issue^[600-developer__tools__git__git-rebase.md].

Automated Rebase on Pull

To minimize conflict complexity, git pull can be configured to automatically rebase local commits on top of the fetched remote changes^[600-developer__tools__git__git-rebase.md]. This avoids the creation of a merge commit for every synchronization.

  • Ad-hoc: Use the flag git pull --rebase^[600-developer__tools__git__git-rebase.md].
  • Configuration: Set git config branch.master.rebase true to make rebase the default behavior for git pull on the master branch^[600-developer__tools__git__git-rebase.md].
  • Global Default: Use git config --global pull.rebase true to apply this behavior to all repositories^[600-developer__tools__git__git-rebase.md].

Error Recovery

If a rebase operation is performed incorrectly (for example, rebasing master onto a feature branch rather than vice versa), the history can be restored^[600-developer__tools__git__git-rebase.md]. The command git reset ORIG_HEAD --hard will revert the repository state to the position before the rebase began^[600-developer__tools__git__git-rebase.md].

  • [[Git merge]]
  • [[Branching strategy]]
  • [[Version control]]

Sources

  • 600-developer__tools__git__git-rebase.md