How to force push a reset to remote repository?

后端 未结 10 1826
生来不讨喜
生来不讨喜 2020-11-29 18:49

Our remote master branch somehow got messed up. Current development code is on the master branch along with the latest commits. Obviously, the development code is not ready

相关标签:
10条回答
  • 2020-11-29 19:10

    I'm using this group of commands to reset my remote repo, this will re-initialize your local repo and relink with your remote repo then force push the updates.

    I think this way won't work in your case, but may be useful for someone else

    go to the source folder then run the commands : note that https://github.com/*.git is your remote repo link

    git init
    git remote add origin https://github.com/*.git
    git add .
    git commit -m "initial commit"
    git push origin master -f
    git push --set-upstream origin master
    

    **Note: this will clear all your git history on your master branch**

    0 讨论(0)
  • 2020-11-29 19:13

    The message means that you're not allowed to do non-fast-forward push.

    Your remote repository has most likely denyNonFastforwards = true in its config. If you change that, git push --force should work.

    To change the setting, you need access to the machine with the remote repository. From there, do git config receive.denynonfastforwards false.

    0 讨论(0)
  • 2020-11-29 19:16

    You're not allowed to do git push that is not fast-forward.

    1. If the remote is GitHub, go to https://github.com/$USER/$REPO/settings/branches and un-protect the branch in question.

      You have to be admin of the repo to do that.

    2. If the remote is your own git server, run git config receive.denynonfastforwards false there.

    0 讨论(0)
  • 2020-11-29 19:18

    Try using the -f flag and putting it after the remote branch name.

    git push origin master -f

    0 讨论(0)
提交回复
热议问题