Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

push changes without pull

Tags:

I'm trying to undo some changes that have already been pushed to a remote repository, and I've done so locally with

git reset --hard COMMIT-HASH 

But now it won't let me push without pulling first, which of course defeats the purpose. I've tried:

git push -f 

Which errors out with:

Total 0 (delta 0), reused 0 (delta 0) remote: error: denying non-fast-forward refs/heads/master (you should pull first) To [email protected]:/yyy.git  ! [remote rejected] master -> master (non-fast-forward) error: failed to push some refs to '[email protected]:/yyy.git' 

So how do I get my new, correct version of the branch to the remote?

like image 262
Will Avatar asked Aug 06 '12 14:08

Will


People also ask

Should I commit my changes before pulling?

If you have uncommitted changes, the merge part of the git pull command will fail and your local branch will be untouched. Thus, you should always commit your changes in a branch before pulling new commits from a remote repository.

Can you push before pulling git?

Always Pull Before a Push Doing so will ensure that your local copy is in sync with the remote repository. Remember, other people have been pushing to the remote copy, and if you push before syncing up, you could end up with multiple heads or merge conflicts when you push.


1 Answers

From the git config man page:

receive.denyNonFastForwards

If set to true, git-receive-pack will deny a ref update which is not a fast-forward. Use this to prevent such an update via a push, even if that push is forced. This configuration variable is set when initializing a shared repository.

The server you are trying to push to has this setting enabled. So, short answer, is that in this case you will not be able to git push --force.


To get the correct version of the branch to the remote, you will have to make a new commit to the tip of the branch that gets it to the correct state. If you are currently at the commit for the correct state, you can run the following:

$ git reset --soft <remote>/<branch>    # point the ref back to the remote, but                                         #   keep the index and working tree  $ git commit                            # make the 'correction' commit $ git push 
like image 143
vergenzt Avatar answered Sep 26 '22 07:09

vergenzt