Thanks, you successfully blew my mind today when I searched what this was, and learned what it was. I can't believe I've been missing out on this.
I have an application for this command today in a work project that will allow me to leave work early, so thanks for the early weekend!
Also, if you're unlucky enough to be using an IDE that doesn't always handle large codebase changes well (e.g., let's say... Xcode), then you've eliminated that problem too.
Some days you work with v1 and some days with v2, and sometimes with main. Sometimes fixes are quick, sometimes not. Sometimes you must switch the working branch while you are in the middle of doing something that is not quite finished.
If you need to change between v1, v2 or main, just change a directory. Done.
So for the above example, setting up this:
cd repo
git checkout -b main origin/main
git worktree add ../v1 origin/v1
git worktree add ../v2 origin/v2
I.e. having a separate worktree for each long running branch makes working with the branches so much easier.Edit: formatting
git-clone --reference /existing/local/repo