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

Re: [PATCH 0/2] worktree: copy-on-write creation and shared-branch worktrees

From
Junio C Hamano <gitster@pobox.com>
Date
Jun 8, 2026, 14:36 UTC
Message-ID
<xmqq8q8pxfny.fsf@gitster.g>
In-Reply-To
<pull.2317.git.git.1780685368.gitgitgadget@gmail.com>
"Jason Newton via GitGitGadget" <gitgitgadget@gmail.com> writes:
Show 5 quoted lines
> When many worktrees share one repository -- e .g. a fleet of agents each
> needing an isolated checkout -- "git worktree add" is costly at scale.
> Objects are shared via the common dir, but the working tree is not: each add
> rewrites every tracked file, so N worktrees cost N full checkouts of disk
> and I/O.

Are the "CoW" semantics offered by these underlying mechanisms, which may differ per operating system and possibly filesystem type, all meant as mere storage-space optimization, or do some of them trade potential space saving with some limitation of the features, i.e., what you can do in the CoW copy and original, or increased runtime cost, either at the clone time or the time of first modification?

What I am trying to get at is why should this be even an opt-in feature. If "cp treeA treeB" at the shell level would make all the files in treeA under identical names and contents in treeB, and let you edit/update/delete copies in either tree without affecting the other tree, then in practice you would not even be able to _tell_ if CoW is in use, no?

It may tilt the scale if there is a downside associated with the use of CoW, like at the first modification of one copy, the system may need to do real copies of other copies, but even such a cost should not be outrageously worse than the cost of copying everything once at the worktree creation time.

So I would understand "whenever we say git_copy_file(A, B), we always use CoW facility under the hood if available, regardless of the purpose of the operation to copy one file to another location--- it may include, but does not have to be limited to, populating working file trees in a new worktree", and I think it is a welcome change.

But I do not quite get "... only if the user gives --reflink option". Why is it even necessary to offer a choice? Especially since you seem to have auto-probe, we should be able to implement a low-level operation to materialize contents identified by a_hash at a_path in the working tree in two different ways, switching on the availablity of CoW, e.g.,

	if (CoW available && we can find existing path with a_hash) {
	        copy-cow the found path to a_path;
	} else {
		write object identified by a_hash to a_path;
	}
>  And a branch can only be checked out in one worktree.

This is a safety feature that has nothing to do with shared files across worktrees, no? Your two worktrees may think they have a checkout of the same branch (thus the same commit), one worktree makes changes and commits, the other worktree suddenly starts seeing a totally different output from its "git diff HEAD" that mixes what it did relative to where it started (which is what we want) plus the reversion of what was done in the other worktree (which is definitely not what we want).

Previous: brian m. carlsonNext: Jason Newton via GitGitGadget
Message 5 of 23 in “worktree: copy-on-write creation and shared-branch worktrees”
  1. 0/2 worktree: copy-on-write creation and shared-branch worktreesJason Newton via GitGitGadget, Jun 5, 2026
  2. 1/2 worktree: add --reflink for copy-on-write worktree creationJason Newton via GitGitGadget, Jun 5, 2026
  3. 2/2 worktree: allow sharing a checked-out branch across worktreesJason Newton via GitGitGadget, Jun 5, 2026
  4. brian m. carlsonJun 5, 2026
  5. Junio C HamanoJun 8, 2026
  6. 0/2 worktree: copy-on-write creation and ephemeral branchesJason Newton via GitGitGadget, Oct 20, 2026
  7. 1/2 worktree: add --reflink for copy-on-write worktree creationJason Newton via GitGitGadget, Oct 20, 2026
  8. brian m. carlsonOct 20, 2026
  9. Jason NewtonOct 21, 2026
  10. brian m. carlsonOct 22, 2026
  11. 2/2 worktree: reap ephemeral branches created by "worktree add"Jason Newton via GitGitGadget, Oct 20, 2026
  12. Eric SunshineOct 21, 2026
  13. Jason NewtonOct 21, 2026
  14. Eric SunshineOct 21, 2026
  15. Jason NewtonOct 21, 2026
  16. Phillip WoodOct 21, 2026
  17. Jason NewtonOct 21, 2026
  18. Eric SunshineOct 21, 2026
  19. 0/4 worktree: copy-on-write creation and ephemeral branchesJason Newton via GitGitGadget, Oct 21, 2026
  20. 1/4 worktree: add --reflink for copy-on-write worktree creationJason Newton via GitGitGadget, Oct 21, 2026
  21. 2/4 worktree: reap ephemeral branches created by "worktree add"Jason Newton via GitGitGadget, Oct 21, 2026
  22. 3/4 worktree: disable reflink on WindowsJason Newton via GitGitGadget, Oct 21, 2026
  23. 4/4 worktree: keep the reflink probe referenced on WindowsJason Newton via GitGitGadget, Oct 21, 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.