Search code examples
gitgithubgit-mergegit-rebase

git conflict with merge but not with rebase


I have a conflict issue that only occures on rebase, but not with merge with GitHub UI.

It happened after trying to reset the current branch to the previous commit, by doing the following commands and then making a PR to rebase to master with GitHub:

git reset --hard HEAD~1
git push origin <myBranch> -f

I tried to pull current master and merge master into my branch but it did not work.

I am not sure why the conflict occur on rebase but not with merge.


Solution

  • I am assuming you made the commit and want to rebase your branch to latest master with your commit on the top.

    Step 1: Update your local master with the upstream master

    git pull upstream master

    Step 2: Checkout to myBranch

    git checkout myBranch

    Step 3: Rebase myBranch with local master

    git rebase master

    If you are getting merge conflict now, this means that there are changes which are conflicting with the changes in myBranch.

    Resolve conflicts with help of editor you are using and then

    git rebase --continue

    Now, your myBranch is updated with latest upstream master.