2

I am trying to squash 5 commits on remote branch mainline. To do so I tried following How to squash commits in git after they have been pushed?. My local mainline branch now has the correct squashed commits. However when I try git push origin +mainline or git push --force origin mainline I get the error

Total 0 (delta 0), reused 0 (delta 0)
remote: To prevent you from losing history, non-fast-forward updates were rejected.
remote: Merge the remote changes (e.g. 'git pull') before pushing again.  See the 'Note
remote: about fast-forwards' section of 'git push --help' for details.
 ! [remote rejected] mainline -> mainline (pre-receive hook declined)

A git status says local and remote have diverged between 1 and 5 commits. Which makes sense I am trying to squash 5 commits on the remote into 1 as a clean up.

Is there something I am doing wrong with this commit history? Since noone is using this branch yet, I can also delete the remote and recreate it.

Community
  • 1
  • 1
Niru
  • 1,407
  • 1
  • 28
  • 47
  • Whoever owns the remote repo is refusing to accept forced pushes. You can push to a new branch there, e.g. `git push origin mainline:newmainline` and ask someone with direct control of the repo to do the overwrite for you. – jthill Aug 02 '16 at 23:51
  • If you can't wait for your admin person to let you do what @jthill indicates and you want to push to mainline and you are ok with leaving the 5 commits on mainline, but still want one on mainline thats the squashed one, you can always git revert the 5 on mainline to get back to the state before you added the 5 and then do your squash commit of the 5 as an additional commit on top of that and then push that up (non force, since it should be fast forward-able now). Your history is still "corrupted" with the 5+1 commits, but you do get your one squash commit on there and you can do that now. – David Neiss Aug 03 '16 at 00:26

0 Answers0