DEV Community

Cover image for 5 steps to resolve merge conflicts in Bitbucket repository with git bash
Jakub Smetanka
Jakub Smetanka

Posted on • Updated on

5 steps to resolve merge conflicts in Bitbucket repository with git bash

Before merging your branch to the main branch (develop, master, whatever), it occurs that your branch is many commits behind the destination branch and somebody pushed changes which have conflicts with yours. Before pushing your changed files you have to sync your branch with the destination branch and in case, that there are files with conflicts you have to resolve them. If you are a fan of git bash or command line, there are 5 steps how to manage merge.

1.Checkout the temporary branch with your changes.

This branch is created, when there are detected conflicts with your origin branch which are not possible to resolve with auto-merging .

git checkout <temporary-branch>
Enter fullscreen mode Exit fullscreen mode

2.Merge destination branch to your detached branch.

git merge remotes/origin/<destination-branch>
Enter fullscreen mode Exit fullscreen mode

This command will merge all files which can merge. In others, there are marked lines of code, which have to be merged manually

3.Resolve conflicts

Compare yours and incoming changes and resolve them. If you have finished, you can mark the resolved file with git add.

git add 'path/resolved-file'
Enter fullscreen mode Exit fullscreen mode

4.Commit resolved files

git commit
Enter fullscreen mode Exit fullscreen mode

If you commit your resolved files you are in the detached branch so you have to push it to your branch.

5.Push detached branch to your branch

git push origin HEAD:<name-of-your-branch>
Enter fullscreen mode Exit fullscreen mode

If it is successful, your branch is in sync with destination branch. You can continue with creating pull request or merging your branch to destination branch.

If you want to support me with coffee you can do it here: Buy Me A Coffee
I would be grateful ;)

Visit website smetankajakub.com

Follow me on Twitter

Photo by Yancy Min on Unsplash

Oldest comments (0)