Git normally refuses pushing to the (single) currently-checked-out branch of a normal, non---bare
repository:
$ git push upstream m
Yes, it is (obviously) a bug: Git's "is this a current branch" test, in the receive pack code, is using the pre-multiple-work-trees test, which is just to check the main work-tree's HEAD
. It needs to be modified to check all work-trees the same way git worktree list
does.
(I'm working on two systems connected via VPN where only one of them has a server running at the moment, so I'm using an asymmetric fetch/push model here.)
Fortunately, I had no uncommitted work, so recovery was trivial: in the secondary work-tree (on branch pytest
), just run:
git reset --hard HEAD
which cleans up both the index and work-tree.
If I were not, however, the easiest trick would be to force a new branch to exist at the previous value of the branch, then check out that branch. This can be done in one step:
git checkout -b tempbranch pytest@{1}
The work-tree would now be on a different (pre-push
) branch, where temporary work can now be committed or stashed or rebased or whatever, and dealt with in the usual way.