Git normally refuses pushing to the (single) currently-checked-out branch of a normal, non---bare
repository:
$ git push upstream master
Counting objects: 1, done.
Writing objects: 100% (1/1), 188 bytes | 0 bytes/s, done.
Total 1 (delta 0), reused 0 (delta 0)
remote: error: refusing to update checked out branch: refs/heads/master
remote: error: By default, updating the current branch in a non-bare repository
remote: error: is denied, because ...
This is correct behavior. See Git push error '[remote rejected] master -> master (branch is currently checked out)'.
However, on that very same upstream, I have an added worktree with a different branch checked out. Just before the above error-demonstration, I ran:
$ git push upstream pytest
and it succeeded, when clearly it should not have, for the same reason master
fails here. In particular, receive.denyCurrentBranch
is indeed set to deny current branches.
On that upstream system, git worktree list
says:
$ git worktree list
<path1> 9febb4c [master]
<path2> 406bef8 [pytest]
which shows that at least part of Git knows that it's checked out. But then it allowed the push anyway, which leads to two questions:
Is this a bug?
Now that I am in this mess, how can I recover?
(Additional note: this bug was fixed in Git 2.26, released in March 2020.)