Search code examples
gitbitbucketgit-merge-conflict

How to merge detached HEAD conflict fixes with original branch?


I had a really out of date sales-refactor branch that I wanted to sync with my master branch. I use bitbucket, and when I go to my sales-refactor branch, I click on Sync Now and it tells me that "This merge has conflicts that must be resolved before it can be committed."

It also gives me some commands I need to run to fix my conflicts (which I did), but now I don't know what to do next to keep my changes that fixed the conflicts (lots of conflicts) into my sales-refactor branch.

I ran these commands following bitbucket's instructions:

git checkout e17ba371fdf3
# Note: This will create a detached head!
git merge remotes/origin/master

Now, I'm on HEAD detached from e17ba371), and I need to get these changes to my sales-refactor branch and push it to my repo.

Can anyone help? I'm not sure exactly how to google for help on this one, so I figured I better give more details in a SO question.


Solution

  • First make sure to do a git fetch, to ensure origin/master is up-to-date in your local repo.

    If you are sure your git log shows the correct history for sales-refactor, you can force push it

    git push --force origin @:sales-refactor
    

    But it is better to reset your local branch first:

    git branch -f sales-refactor @
    

    Then force push it:

    git checkout sales-refactor
    git push -f