Git: How to ignore fast forward and revert origin [branch] to earlier commit?

To add to my previous answer, and to address the fact that a forced git push can really mess up other contributors’ local repos, git 1.8.5 (upcoming Q4 2013) will see a new option:

git push --force-with-lease

See the origin of that option in this thread:

if something happens at ‘origin‘ to the branch you are forcing or deleting since you fetched to inspect it, you may end up losing other people’s work.

Somebody who is unaware of the decision to rewind and rebuild the branch may attempt to push to the branch between the time you fetched to rebase it and the time you pushed to replace it with the result of the rebasing.

We can make these pushes safer by optionally allowing the user to tell “git push” this:

I am forcing/deleting, based on the assumption that the value of ‘branch’ is still at this object.
If that assumption no longer holds, i.e. if something happened to the branch since I started preparing for this push, please do not proceed and fail this push.

You can see the full documentation of --force-with-lease in commit 28f5d17

--force-with-lease will protect all remote refs that are going to be updated by requiring their current value to be the same as some reasonable default, unless otherwise specified;

For now, “some reasonable default” is tentatively defined as “the value of the remote-tracking branch we have for the ref of the remote being updated”, and it is an error if we do not have such a remote-tracking branch.

That explain the “lease” part of that option:

force-with-lease“: You assume you took the lease on the ref when you fetched to decide what the rebased history should be, and you can push back only if the lease has not been broken.


This is already being tested, and mentioned in the “What’s cooking in git.git (Aug 2013, #07; Wed, 28)“:

By the way, the push that overrides the usual “must fast-forward” was done using the “force-with-lease” option that has been cooking in next, like so:

$ git fetch ko next
$ anchor=$(git rev-parse --verify FETCH_HEAD)
$ for remote in ko repo gph github2
  do
    git push --force-with-lease=refs/heads/next:$anchor $remote next
  done

Note: “git push --force-with-lease” has been taught to report if the push
needed to force (or fast-forwarded).

So this command is more detailed in its output with git 2.8 (March 2016)

push: fix ref status reporting for --force-with-lease

The --force--with-lease push option leads to less detailed status information than --force.
In particular, the output indicates that a reference was fast-forwarded,
even when it was force-updated.


Beware of that option being ignored/bypassed, as explained in Git 2.13 (Q2 2017).

Leave a Comment