til

Today I Learned: collection of notes, tips and tricks and stuff I learn from day to day working with computers and technology as an open source contributor and product manager

View project on GitHub

Git Worktrees

I heard about these magic worktrees in some conversation on a podcast. Now I finally got around to using them.

They are indeed magical, or let’s just say, incredibly useful. I have added a resource, which I believe is a good explanation, but a tad too long, since git worktrees are very basic, but very useful.

The gist:

You are working in something in a branch in your git work directory.

An urgent distraction enters, so you do:

git worktree add  ../attention distraction

This creates a directory outside your current working directory named: attention with a branch named distraction defaulting to head

You can jump to the newly created directory:

cd ../attention

The worktree is per repository and you can see your existing worktrees doing:

git worktree list

And when done being distracted:

git worktree remove ../attention

There are many more powerful options and the above just covers the basic, so do check the official documentation.

Resources and References