Repository navigation
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
freespace.shnow makes every linked git worktree share disk blocks with its main checkout on macOS. On a large monorepo checkout with 27 worktrees, this shared 47.7G (about 1.8G per worktree) without deleting anything. During one pass, free space rose 29.5G.Why
Each worktree holds its own full copy of every tracked file. With many agent worktrees, that duplication is often the biggest thing on the disk, and it isn't a cache that can be deleted.
APFS can store a file as a clone: a copy that shares the original's disk blocks and only uses new space for blocks that later change. A clone behaves exactly like an ordinary independent file. Editing it in one worktree never changes another.
What changes
scripts/clone-worktree-files.py(Python standard library only). For each linked worktree it replaces every tracked file that matches the main checkout with a clone of it. A file matches when both indexes record the same blob and mode andgit diff-filessees it unmodified on both sides.--verify-bytesalso compares the bytes.renamex_npwithRENAME_SWAP), undone if the file was written after it was checked.git statusnever shows them.index.lockwhile re-hashing.freespace.shruns it aftergit gcfor each main checkout with linked worktrees and reports the amount shared (-nreports what it would share).Notes
duand Finder still count every clone in full; only free space (df) shows the saving. Savings shrink as files diverge, and rerunning re-shares them.sparse-branch.sh. The two merge in either order.Testing
git addduring the index refresh was kept. SIGTERM mid-run left no temp files.git statusclean.bash -n.freespace.sh -non my laptop exited 0. After the run above it reported 1.8G still shareable in the large repo (a worktree that was busy earlier), plus 7M and 5M in two small repos with worktrees.