git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 0/2] worktree: treat a branch being rebased or bisected as checked out

From
JMJasper Mayone <me@jaspermayone.com>
Date
Oct 30, 2026, 14:21 UTC
Message-ID
<20261030142137.54750-1-me@jaspermayone.com>
In-Reply-To
<20261024165311.57387-1-me@jaspermayone.com>

This replaces my "git worktree list --branch" patch [1]. In that thread Kristoffer pointed out that "git for-each-ref --merged <commit> --format='%(worktreepath)' refs/heads/" already finds the worktrees of merged branches, so a new option is not needed. What is missing is that %(worktreepath) ignores a branch while a worktree is rebasing or bisecting it, although "git worktree add" and "git branch -d" already treat that branch as checked out. Phillip agreed that this is a bug.

Ben then asked what happens if such a worktree is passed to "git worktree remove". Today it is removed, and the rebase or bisect state is lost with it, if the files happen to be clean. Phillip called that a bug too, and more likely to be hit once %(worktreepath) reports these worktrees, so it is fixed first.

 1/2 makes "git worktree remove" refuse a worktree in the middle of a
     rebase, "git am", bisect, or cherry-pick or revert sequence,
     unless --force is given.
 2/2 makes %(worktreepath), and so the "+" marker of "git branch",
     name the worktree that is rebasing or bisecting a branch, as
     prepare_checked_out_branches() in branch.c does. Branches that
     "rebase --update-refs" will move are not included.
Two things reviewers may want to decide differently:
 * In the worktree that is doing the rebase, "git branch" now shows
   both "* (no branch, rebasing topic)" and "+ topic". I documented
   that rather than special-case the current worktree in the format
   that "git branch" builds, because %(worktreepath) itself should not
   depend on where it is run. If you would rather hide the "+" there,
   I can do that in "git branch" instead.
 * A merge stopped with --no-commit is not checked by 1/2. Its staged
   changes already make "git status" report the worktree as unclean in
   the common case.
[1] https://lore.kernel.org/git/20261024165311.57387-1-me@jaspermayone.com/
Jasper Mayone (2):
  worktree remove: refuse a worktree in the middle of a rebase or bisect
  ref-filter: name the worktree of a branch being rebased or bisected
 Documentation/git-branch.adoc       |  5 ++-
 Documentation/git-for-each-ref.adoc |  4 +-
 Documentation/git-worktree.adoc     | 11 +++--
 builtin/worktree.c                  | 31 +++++++++++++-
 ref-filter.c                        | 60 +++++++++++++++++++++------
 t/t2403-worktree-move.sh            | 59 +++++++++++++++++++++++++++
 t/t3203-branch-output.sh            | 35 ++++++++++++++++
 t/t6302-for-each-ref-filter.sh      | 63 +++++++++++++++++++++++++++++
 8 files changed, 249 insertions(+), 19 deletions(-)
base-commit: b9e5cff1803ab24582201ef059516eb16014b9d9
-- 
2.56.0
Previous: Phillip WoodNext: Jasper Mayone
Message 16 of 24 in “worktree list: add --merged and --no-merged”
  1. 0/1 worktree list: add --merged and --no-mergedJasper Mayone, Oct 21, 2026
  2. 1/1 worktree list: add --merged and --no-mergedJasper Mayone, Oct 21, 2026
  3. Junio C HamanoOct 23, 2026
  4. Eric SunshineOct 24, 2026
  5. worktree list: add --branch to select worktrees by branchJasper Mayone, Oct 24, 2026
  6. Phillip WoodOct 25, 2026
  7. Phillip WoodOct 26, 2026
  8. Eric SunshineOct 28, 2026
  9. Junio C HamanoOct 28, 2026
  10. Kristoffer HaugsbakkOct 28, 2026
  11. Jasper MayoneOct 29, 2026
  12. Eric SunshineOct 29, 2026
  13. Phillip WoodOct 29, 2026
  14. Ben KnobleOct 29, 2026
  15. Phillip WoodOct 29, 2026
  16. 0/2 worktree: treat a branch being rebased or bisected as checked outJasper Mayone, Oct 30, 2026
  17. 1/2 worktree remove: refuse a worktree in the middle of a rebase or bisectJasper Mayone, Oct 30, 2026
  18. 2/2 ref-filter: name the worktree of a branch being rebased or bisectedJasper Mayone, Oct 30, 2026
  19. Junio C HamanoOct 30, 2026
  20. Jasper MayoneOct 30, 2026
  21. Harald NordgrenOct 21, 2026
  22. Junio C HamanoOct 21, 2026
  23. Harald NordgrenOct 22, 2026
  24. Kristoffer HaugsbakkOct 22, 2026

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.