Note that this error message won't apply just to your current branch, but to any branch checked out as a worktree.
"git fetch
"(man) without the --update-head-ok
option ought to protect a checked out branch from getting updated, to prevent the working tree that checks it out to go out of sync.
The code was written before the use of "git worktree
"(man) got widespread, and only checked the branch that was checked out in the current worktree, which has been updated with Git 2.35 (Q1 2022).
See commit 593a2a5, commit 9fdf4f1, commit 38baae6, commit 8bc1f39, commit c8dd491, commit 7435e7e, commit c25edee, commit 66996be (01 Dec 2021) by Anders Kaseorg (andersk
).
(Merged by Junio C Hamano -- gitster
-- in commit 13fa77b, 21 Dec 2021)
fetch
: protect branches checked out in all worktrees
Signed-off-by: Anders Kaseorg
Refuse to fetch into the currently checked out branch of any working tree, not just the current one.
Fixes this previously reported bug.
As a side effect of using find_shared_symref,
we'll also refuse the fetch when we're on a detached HEAD because we're rebasing or bisecting on the branch in question.
This seems like a sensible change.
With Git 2.37 (Q3 2022), the way "git fetch
"(man) without --update-head-ok
ensures that HEAD in no worktree points at any ref being updated was too wasteful, which has been optimized a bit.
See commit f7400da (16 May 2022) by Orgad Shaneh (orgads
).
(Merged by Junio C Hamano -- gitster
-- in commit 5ed49a7, 25 May 2022)
fetch
: limit shared symref check only for local branches
Signed-off-by: Orgad Shaneh
This check was introduced in 8ee5d73 ("Fix fetch/pull when run without --update-head-ok
", 2008-10-13, Git v1.6.1-rc1 -- merge) in order to protect against replacing the ref of the active branch by mistake, for example by running git fetch origin master:master
(man) .
(see "Why "git fetch origin branch:branch
" works only on a non-current branch?")
It was later extended in 8bc1f39 ("fetch
: protect branches checked out in all worktrees", 2021-12-01, Git v2.35.0-rc0 -- merge listed in batch #4) to scan all worktrees.
This operation is very expensive (takes about 30s in my repository) when there are many tags or branches, and it is executed on every fetch, even if no local heads are updated at all.
Limit it to protect only refs/heads/*
to improve fetch performance.
git remote add name server
, perhaps with the--mirror
option. – Keldah.git/config
. In particular, Charles is talking about the[remote …]
section, I believe. – Mizzen