
This check was introduced in 8ee5d73 ("Fix fetch/pull when run without -update-head-ok",, 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). (Merged by Junio C Hamano - gitster - in commit 5ed49a7, ) fetch: limit shared symref check only for local branches See commit f7400da () by Orgad Shaneh ( orgads). 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. Refuse to fetch into the currently checked out branch of any working tree, not just the current one.Īs 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. (Merged by Junio C Hamano - gitster - in commit 13fa77b, ) fetch: protect branches checked out in all worktrees See commit 593a2a5, commit 9fdf4f1, commit 38baae6, commit 8bc1f39, commit c8dd491, commit 7435e7e, commit c25edee, commit 66996be () by Anders Kaseorg ( andersk).

#Git fetch a branch code#
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).

" 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. Note that this error message won't apply just to your current branch, but to any branch checked out as a worktree.
