What would I use git-worktree for?

I read Github’s post on git-worktree. They write:

Suppose you’re working in a Git repository on a branch called feature, when a user reports a high-urgency bug in master. First you create a linked working tree with a new branch, hotfix, checked out relative to master […] You can fix the bug, push hotfix, and create a pull request.

When I’m working on a branch called feature and some high-urgency bug in master is reported, I usually stash away whatever I’m working on and create a new branch. When I’m done, I can continue working. This is a very simple model, I’ve been working like that for years.

On the other hand, using git-worktree has its own limitations:

For example, it’s not allowed to have the same branch checked out in two linked working trees at the same time, because that would allow changes committed in one working tree to bring the other one out of sync.

Why would I choose a more complicated workflow for a problem that’s already been solved?

Is there anything about git-worktree that couldn’t be done beforehand and that justifies this whole new, complex feature?

10 Answers
10

Leave a Comment