Resolve conflicts during Git merge and rebase

vishal_bhavsar

Vishal Bhavsar

Posted on July 5, 2024

Resolve conflicts during Git merge and rebase

Say, you have main & feature as 2 branches.

Merge conflicts

If you want to merge feature branch into main, run following command.

git checkout main
git merge feature
Enter fullscreen mode Exit fullscreen mode

This can result in merge conflicts.

To discard all changes in feature and accept everything on main, run following command.

git merge -Xours feature
Enter fullscreen mode Exit fullscreen mode

To accept changes from feature branch, run below command.

git merge -Xtheirs feature
Enter fullscreen mode Exit fullscreen mode

Rebase conflicts

If you want to rebase feature branch onto main, run below command.

git checkout feature
git rebase main
Enter fullscreen mode Exit fullscreen mode

Again, this can result in merge conflicts.
To accept the changes in feature branch, run below command.

git rebase main -Xtheirs
Enter fullscreen mode Exit fullscreen mode

To accept the changes in main branch, run below command.

git rebase main -Xours
Enter fullscreen mode Exit fullscreen mode
💖 💪 🙅 🚩
vishal_bhavsar
Vishal Bhavsar

Posted on July 5, 2024

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related