Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git: Why does "--force-with-lease" with an explicit SHA work differently than the implicit version?

Tags:

git

While using "git push --force-with-lease", I encountered a behavior that I do not understand. According to the documentation (https://git-scm.com/docs/git-push), you can specify a SHA-1 value explicitly on the command line, or you can leave it out, in which case git will be "requiring its current value to be the same as the remote-tracking branch we have for it".

Specifically, if I do git push --force-with-lease=preflight/myname origin develop:preflight/myname, git says Updates were rejected because the tip of the remote-tracking branch ...

But if I look up the SHA of .git/refs/remotes/origin/preflight/myname explicitly (let's say it is 7528290003ef5b36f9f6446c91cb4a3ddb20c0c2) and then do git push --force-with-lease=preflight/myname:7528290003ef5b36f9f6446c91cb4a3ddb20c0c2 origin develop:preflight/myname, git pushes successfully.

I would have expected both calls to result in the same behavior. What am I missing?

like image 712
T. Baum Avatar asked Feb 02 '26 07:02

T. Baum


1 Answers

I found out the reason myself: In the config, push.useforceifincludes=true was set.

This means that without an explicit hash, "--force-with-lease" behaves as if "--force-if-includes" was also set and, therefore, behaves differently than the option with an explicit hash.

like image 145
T. Baum Avatar answered Feb 04 '26 00:02

T. Baum



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!