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

[PATCH v4 2/4] doc: for-each-ref: say how to read %(worktreepath) safely

From
JMJasper Mayone <me@jaspermayone.com>
Date
Nov 2, 2026, 18:29 UTC
Message-ID
<20261102182930.3511-3-me@jaspermayone.com>
In-Reply-To
<20261102182930.3511-1-me@jaspermayone.com>

The path that %(worktreepath) gives can contain a newline, which breaks a script that reads one record per line. Say how to avoid that: use a quoting option, or end the atom with %00 and look for the NUL before the LF that ends the record.

Also say that only one worktree is shown when a branch is checked out in more than one worktree.

Suggested-by: Phillip Wood <phillip.wood123@gmail.com>
Signed-off-by: Jasper Mayone <me@jaspermayone.com>
---
 Documentation/git-for-each-ref.adoc | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/Documentation/git-for-each-ref.adoc b/Documentation/git-for-each-ref.adoc
index a7b31e8aaf..9247737aa7 100644
--- a/Documentation/git-for-each-ref.adoc
+++ b/Documentation/git-for-each-ref.adoc
@@ -183,7 +183,12 @@ but if used together the last option is selected.
 `worktreepath`::
 	The absolute path to the worktree in which the ref is checked
 	out, if it is checked out in any linked worktree. Empty string
-	otherwise.
+	otherwise. If the ref is checked out in more than one worktree,
+	only one of them is shown. The path can contain a newline, so
+	use one of the quoting options such as `--shell`, or follow
+	`%(worktreepath)` with `%00` and parse the output by looking for
+	the `NUL` after the path and then for the `LF` that ends each
+	record.
 
 `ahead-behind:<commit-ish>`::
 	Two integers, separated by a space, demonstrating the number of
-- 
2.56.0
Previous: Jasper MayoneNext: Jasper Mayone
Message 27 of 33 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. Phillip WoodNov 2, 2026
  19. Jasper MayoneNov 2, 2026
  20. 2/2 ref-filter: name the worktree of a branch being rebased or bisectedJasper Mayone, Oct 30, 2026
  21. Phillip WoodNov 2, 2026
  22. Jasper MayoneNov 2, 2026
  23. Junio C HamanoOct 30, 2026
  24. Jasper MayoneOct 30, 2026
  25. 0/4 worktree: treat a branch being rebased or bisected as checked outJasper Mayone, Nov 2, 2026
  26. 1/4 worktree remove: refuse a worktree in the middle of an operationJasper Mayone, Nov 2, 2026
  27. 2/4 doc: for-each-ref: say how to read %(worktreepath) safelyJasper Mayone, Nov 2, 2026
  28. 3/4 ref-filter: name the worktree of a branch being rebased or bisectedJasper Mayone, Nov 2, 2026
  29. 4/4 branch: do not mark the branch the current worktree is rebasingJasper Mayone, Nov 2, 2026
  30. Harald NordgrenOct 21, 2026
  31. Junio C HamanoOct 21, 2026
  32. Harald NordgrenOct 22, 2026
  33. 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.