TheWebs
TheWebs

Reputation: 12923

How to avoid doing a pull in git after a git reset --hard

So I did:

git reset --hard #commithash
# make a bunch of changes, fixes and so on.
git add -A
git commit -a
# message
git push 

But I am getting:

error: failed to push some refs to 'privateurlofrepohere'
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.

I do not want to pull as that will mess everything up. So whats the next step or the proper step to get my new changes up to the repo?

Upvotes: 2

Views: 2585

Answers (2)

eftshift0
eftshift0

Reputation: 30212

The remote branch as it is right now and your current branch have actually diverged. In order to tell git to forget about what is currently on the remote and leave it as you have it on your local branch is by using git push --force. This will "obliterate" the (remote) branch as it was so use with care (you will get the previous ID of the revision, just in case you wanted it back).

Upvotes: 3

merlin2011
merlin2011

Reputation: 75555

If you want to keep your commits without a merge commit, you can rebase your commits on top of the current tip instead.

git pull --rebase

Upvotes: 1

Related Questions