1

I am trying to hard reset the master branch, so it mirrors the current state of our ‘develop’ branch.

We do not care for any old commits on master and want to rewrite it’s history. I should note, that we are using a self-hosted Git server called ‘SCM-Manager’ (no GitHub or similar services). I do have ‘owner’ privileges on the repository.

I am using the following command to force push the Develop’s state to Master:

git push origin +develop:master --no-verify --force

But I keep getting this error message:

! [rejected]            develop -> master (non-fast-forward)
error: failed to push some refs to 'https://****.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

Any help is highly appreciated.

Jonas_Hess
  • 1,874
  • 1
  • 22
  • 32
  • 1
    The `master -> master` in the error message means your Git attempted to set their `master` to the same commit hash that is stored in your `master`. But your `git push origin +develop:master` should have your Git using the hash stored in your `develop`. Something here does not add up, in other words. – torek May 13 '19 at 09:55
  • @torek You are right, the error message I provided was generated with my head on master. I edited the question, but the problem remains. – Jonas_Hess May 13 '19 at 10:03
  • Should I approach this differently, like deleting the master branch and then recreating it from develop? – Jonas_Hess May 13 '19 at 10:08
  • Have you checked the `receive.denyFastForwards` git config variable in your server repo? This config variable could cause the server repo to reject. I don't think this is the case, though, because the error message is (at least for me) different when the push is rejected because of that config variable. – Alderath May 13 '19 at 10:52
  • Just to be sure, this is not about the order of paramters? I.e. `--force` that has to be in front of `[ […​]]`, like in `git push --no-verify --force origin +develop:master`. – kowsky May 13 '19 at 10:59
  • No, Git parses the options almost anywhere here. The `+` in the refspec means force regardless of the `--force` flag. (Perhaps you're using something other than just the command line to do the push?) – torek May 13 '19 at 15:26

2 Answers2

0

I solved the issue by removing the ‘master’ branch as the default branch in the SCM-Manager console.

enter image description here

This allowed me to delete and then recreate the branch as a copy of the 'develop' branch.

Jonas_Hess
  • 1,874
  • 1
  • 22
  • 32
-1

As the error message says: git pull before you try to git push. Apparently your local branch is out of sync with your tracking branch.

Lorenzo
  • 15
  • 7
  • 4
    The OP doesn't want to sync up, he wants to overwrite. The command he showed is a correct one (the `--no-verify --force` part should be unnecessary in general but also harmless here). – torek May 13 '19 at 09:57
  • My view is that local master branch should be in sync with origin master before making any change in origin master. – Anshul Singhal May 13 '19 at 10:09