2

In the project we have a main repo with master branch MAINREPO/master (upstream). My team has a fork MYTEAM (origin). We aggried that we use MYTEAM/masteronly synchronize with MAINREPO/master:

1. git checkout master 
2. git fetch upstream 
3. git rebase upstream/master 
4. git push

But of course, somebody broke this rule and accidentally commited to MYTEAM/master (origin/master). And now, 4. git push fails. My first idea was to use git push origin master -f but it seems that my remote forbids that:

remote: error: GH003: Sorry, force-pushing to master is not allowed. ! [remote rejected] master -> master (pre-receive hook declined)

I'm not and admin of my enterprise github so I guess I can do nothing about it? Anyway, how can I fix my origin master?

dragonfly
  • 17,407
  • 30
  • 110
  • 219
  • You'll need to get the right to push force if you want to change the history, otherwise you'll have to find another way - that will leave you with a dirty history. I'd go for the first option and make sure that everyone who has downloaded the changes correctly updates his repos. If it's a public repo, you can probably forget about that. – Thibault D. Mar 17 '16 at 14:19

1 Answers1

1

Read this out: How to move HEAD back to a previous location? (Detached head)

The best way wil be to use git reflog and then checkout the last good point,

or

to rename the current branch and check it out again.


Git reflog

Using the git reflog you can view all your git history which modified your HEAD.
Find out the desired commit, checkout to this point and fix whatever you need from this point.

Community
  • 1
  • 1
CodeWizard
  • 128,036
  • 21
  • 144
  • 167
  • Hi - the issue is with remote branch - I fixed the branch locally by moving the HEAD of my local repository/master to correct place. But I still cannot push it to the remote because remote master and my local master branched out. – dragonfly Mar 17 '16 at 12:28
  • If yu cant force push do a revert and then a simple push – CodeWizard Mar 17 '16 at 13:16
  • @CodeWizard but that will contain the messed up history. – David T. May 20 '16 at 00:50