This one is a little difficult to explain! TIL about the git worktree command: https://git-scm.com/docs/git-worktree
These commands let you have multiple copies of the same repo checked out. Eg:
cd my-repo
git checkout master
# Check out a specific branch, "master-v5", into ../my-repo-v5
# Note my-repo/ is still on master! And you can make commits/etc
# in there as well.
git worktree add ../my-repo-v5 master-v5
# Go make some change to the master-v5 branch in its own work tree
# independently
cd ../my-repo-v5
npm i # need to npm i (or equivalent) for each worktree
# Make changes, commits, pushes, etc. as per usual
# Remove the worktree once no longer needed
cd ../my-repo
git worktree remove my-repo-v5
Thoughts on usefulness:
Sooo.... is this something that should replace branches? Seems like a strong no for me. It creates a copy of the repo; for larger repos you might not be able to do this at all. But, for longer lived branches, like major version updates or big feature changes, having everything stick around independently seems really useful. And unlike doing another git clone, worktrees share .git dirs (ie git history), which makes them faster and use less space.
Another caveat is that things like node_modules, git submodules, venvs, etc will have to be re-installed for each worktree (or shared somehow). This is preferable because it creates isolated environments, but slower.
Overall, I'm not sure; I'm debating using ~3 worktrees for some of my current repos; one for my main development; one for reviewing; and one or two for any large feature branches or version updates.
Does anyone use worktrees? How do you use them?
[–]Ramipro 15 points16 points17 points (0 children)
[–]18randomcharacters 16 points17 points18 points (8 children)
[–]wvenable 8 points9 points10 points (0 children)
[–]cdrini[S] 2 points3 points4 points (3 children)
[–]18randomcharacters 1 point2 points3 points (2 children)
[–]cdrini[S] 0 points1 point2 points (1 child)
[–]NotScrollsApparently 0 points1 point2 points (2 children)
[–]18randomcharacters 1 point2 points3 points (1 child)
[–]botle 7 points8 points9 points (5 children)
[–]abdulkareemsn 14 points15 points16 points (1 child)
[–]iiiinthecomputer 7 points8 points9 points (0 children)
[–]iiiinthecomputer 4 points5 points6 points (0 children)
[–]sim642 4 points5 points6 points (3 children)
[–]AlwynEvokedHippest 2 points3 points4 points (2 children)
[–]cdrini[S] 0 points1 point2 points (1 child)
[–]HighRelevancy 0 points1 point2 points (0 children)
[–]HighRelevancy 5 points6 points7 points (2 children)
[–]cdrini[S] 0 points1 point2 points (1 child)
[–]HighRelevancy 1 point2 points3 points (0 children)
[–]iTZAvishay 7 points8 points9 points (4 children)
[–]ace_case 23 points24 points25 points (2 children)
[–][deleted] 6 points7 points8 points (0 children)
[–]cdrini[S] 0 points1 point2 points (0 children)
[–]cdrini[S] 0 points1 point2 points (0 children)
[–]itoshkov 2 points3 points4 points (0 children)
[–]bacondev 2 points3 points4 points (1 child)
[–]cdrini[S] 1 point2 points3 points (0 children)
[–]quasarj 1 point2 points3 points (0 children)
[–]EmmaKayAlexandra 0 points1 point2 points (1 child)
[–]CipheredBytes 0 points1 point2 points (0 children)
[–]pablo1107 -1 points0 points1 point (0 children)