pushed a commit to origin/master on github, when the git branch is origin/foo

Issue

I have a branch foo in my local git repository.
I made a commit to this foo.

I’m using emacs and magit to manage my git repository.
I pushed to my github repo, origin but accidentally pushed to origin/master rather than origin/foo.

I want to move that commit to origin/foo. Nothing about the local git repository needs to change, as it is correct, it is just the github version that is incorrect.

Solution

From your comment, you now have foo as remote tracking branch of origin/master. You need to fix that to avoid future confusion: git checkout foo, then git push --set-upstream origin foo.

Then you need to reset master on the remote repo. You do this by pushing your local master there. Since that would result in potentially losing data on the remote repo, git will complain. So you need to force it: git push -f origin master.

Answered By – Gauthier

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published