billben.net


Git Worktrees

I keep all my worktrees in ~/worktrees/ and all my repos in ~/repos/.

🆕 Creating a worktree

Change directory into your ~/repos/[repo-name] and run the following to:

git worktree add -b [new branch name] [path to worktree] [commit/branch]

💥 Listing worktrees

List out what worktrees exist:

git worktree list
~/repos/service_name                      0000000 [master]
~/worktrees/service_name__branch_name     0000001 [feat/new_feature_one]

If you list your branches you can see which ones are worktrees (denoted by the +):

git branch
  feat/new_feature_one
+ feat/new_feature_two
* master

Cleaning up

Once you’ve merged your branch, make sure you clean up after yourself:

git worktree remove [path to worktree]

😛 Gotchas