- Happen often
- Learning to fix conflicts is hard
- Practice makes perfect
- Force push after fixing conflicts. Be careful!
- Check out a new branch and edit
conflicts.rb. Add ‘Line4’ and ‘Line5’.
- Commit and push.
- Check out
conflicts.rb. Add ‘Line6’ and ‘Line7’ below ‘Line3’.
- Commit and push to
- Create a merge request and watch it fail.
- Rebase our new branch with
- Fix conflicts on the
- Stage the file and continue rebasing.
- Force push the changes.
- Finally continue with the merge request.
git checkout -b conflicts_branch # vi conflicts.rb # Add 'Line4' and 'Line5' git commit -am "add line4 and line5" git push origin conflicts_branch git checkout main # vi conflicts.rb # Add 'Line6' and 'Line7' git commit -am "add line6 and line7" git push origin main
Create a merge request on the GitLab web UI, and a conflict warning displays.
git checkout conflicts_branch git fetch git rebase main # Fix conflicts by editing the files. git add conflicts.rb # No need to commit this file git rebase --continue # Remember that we have rewritten our commit history so we # need to force push so that our remote branch is restructured git push origin conflicts_branch -f
- When to use
git mergeand when to use
- Rebase when updating your branch with
- Merge when bringing changes from feature to
- Reference: https://www.atlassian.com/git/tutorials/merging-vs-rebasing