By default 'git history' also rewrites every local branch descending from the commit it changes. Aniket Gupta's patch notes that if another worktree has such a branch checked out, the branch moves but that worktree's index and working tree stay behind and show staged changes nobody made. 'git branch -f' refuses to move such branches and 'git rebase --update-refs' skips them, so the patch refuses to proceed if any affected branch is used by a worktree.

Toon Claes read the comment above is_shared_symref() and pointed out a gap: a branch checked out in another worktree that has an ongoing rebase or bisect is not detected. He posted a test reproducing it. Gupta confirmed that 'git history drop --update-refs=head second' exits 0 and moves 'other', after which the rebase in the other worktree fails with a 'cannot lock ref' error. A branch another worktree's 'rebase --update-refs' is going to update is missed, as is the default mode when that worktree rebases a detached HEAD. He says he will try to close this in builtin/history.c by also reading the update-refs state of other worktrees.

Phillip Wood asked for documentation changes: finish the sentence about advice rather than describing the advice, and split the reasons by case. A branch used by another worktree cannot be rewritten because that worktree's index and working tree would not match. A branch being rebased in the current worktree cannot be rewritten because the rebase would fail. Gupta agreed to group the reasons by what is happening to the branch.

Wood also wondered whether a helper such as branch_used_elsewhere() would be better placed in branch.c, built around register_checked_out_branch(), noting that 'git checkout' calls branch_checked_out() but probably wants to know whether a branch is in use elsewhere. Gupta replied that branch.c already tracks checkout, rebase, bisect and --update-refs, and proposed leaving 'git checkout' (which goes through die_if_checked_out() and does not see --update-refs targets) for a later patch. A v3 is planned.