Hacker News new | ask | show | jobs
by nasretdinov 20 days ago
You can also have multiple independent git repos that don't duplicate the full object store, via git clone --reference. It's less relevant in the container era, but otherwise it can save a lot of time and disk space when cloning repos repeatedly
2 comments

Oh, that's actually really useful for my... inefficient clone of nixpkgs and the linux kernel...
Interesting; how's it compare to work trees?
Worktrees effectively share the entire state of the repo. Only limitation is that a branch can only be checked out in one repo at a time.

Clones only share the immutable object store

For most practical uses of same repo checking out different branches locally, worktrees are better.

The nice thing about clones is that you can have a backup clone, a wip clone, a review clone where you don't clutter the amount of local branch refs

ofc if you're running AI agents in YOLO mode — clones means you don't need to worry that Sonnet is going to see your .git/index.lock file and go "this is blocking me, let's rm -f this" and corrupt all your work that you never bothered pushing
Worktrees are different checkouts of the same repo. Clone with --reference is a separate repo altogether, with its own .git and worktree.