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:
- Identify and resolve conflicts: Edit the conflicting files to fix the differences.
- Stage the resolution: Use
git add .orgit add <conflicted_files>to mark the conflicts as resolved. - Continue the rebase: Run
git rebase --continueto 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:
- Fetch the latest changes (
git fetch). - Start the rebase (
git rebase). - Resolve conflicts and add files (
git add). - Continue the rebase (
git rebase --continue). - 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 truesets the master branch to rebase by default^[600-developer-tools-git-git-rebase.md:62]. - Global:
git config --global pull.rebase trueapplies rebase to all branches by default^[600-developer-tools-git-git-rebase.md:75]. - Automatic setup:
git config --global branch.autoSetupRebase alwaysensures new branches automatically favor rebase^[600-developer-tools-git-git-rebase.md:76].
Related Concepts¶
- [[Git merge]]
- [[Version control]]
Sources¶
600-developer-tools-git-git-rebase.md