2

I pushed a change to a remote test git repo, then reset my local git repo to HEAD^, and now am trying to push my local repo to origin, but I get a "non fast forward" merger warning. If I do a git pull, my local repo gets nuked by the origin.

How can I either merge in the origin repo and tell it to throw away the merges from the origin or tell origin to accept my push, even though it is not a fast forward?

Thanks

Tyler DeWitt
  • 23,366
  • 38
  • 119
  • 196

1 Answers1

1

The GitHub help page does summarize it nicely:

This error can be a bit overwhelming at first, do not fear.
Simply put, git cannot make the change on the remote without losing commits, so it refuses the push.
Usually this is caused by another user pushing to the same branch.
You can remedy this by fetching and merging the remote branch, or using pull to perform both at once.

In other cases this error is a result of destructive changes made locally by using commands like git commit --amend or git rebase.

(In your case, a git reset --hard)

While you can override the remote by adding --force to the push command, you should only do so if you are absolutely certain this is what you want to do.
Force-pushes can cause issues for other users that have fetched the remote branch, and is considered bad practice.
When in doubt, don’t force-push.

The question "Git reset --hard and a remote repository" adds that you need to be aware of the potential remote config receive.denyNonFastForwards, which can deny your "git push --force".
In which case, some kind of revert needs to take place: alternatives are discussed at "GIT revert to previous commit… how?".

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250