Mid-feature and an urgent fix lands? Use git worktree, not stash
git worktree gives you a second working folder for the same repository, with another branch in it. You fix the urgent issue there, and your original work stays as it is, with no stash and no half-done commit.

You are in the middle of a new feature, with ten modified files and nothing finished, and an urgent fix lands on the main branch. The usual answer is git stash or a half-done commit, then coming back and trying to remember what you were doing. There is another way: a second folder for the same repository, with the branch you need in it, while your work stays open where it is.
What is git worktree?
git worktree is a Git command that lets one repository have more than one working folder, each with a different branch, at the same time. Each folder is called a worktree.
The official git worktree documentation says a repository can support multiple working trees, so you can check out more than one branch at a time. The new folder is linked to the same repository and shares everything with it, except per-worktree files such as HEAD and the index.
In business-owner terms: think of a desk with two drawers for the same archive. You open a file in the second drawer and finish it, and your papers on the first desk stay open exactly as you left them.
Why is it better than stash for an urgent fix?
A worktree is better than stash for an urgent fix because it never touches your open work. Nothing is hidden and brought back, so there is no conflict waiting for you, and no file you forget you stashed.
There is a second benefit: you can run the server or the tests in both folders at the same time, and compare the old behavior with the new one side by side.
How do you create a worktree for an urgent fix?
You create a worktree with git worktree add and the path of the new folder, plus -b if you want a new branch. According to the docs, -b creates the new branch from the starting point you give it, and from HEAD if you give none.
From your project folder, create a folder next to it with a new branch from
main:
git worktree add -b hotfix/login ../myapp-hotfix mainGo to the new folder, fix the issue, then commit and push as usual:
cd ../myapp-hotfix
git commit -am "Fix login redirect"
git push -u origin hotfix/loginGo back to your original folder, and your modified work is still there as you left it:
cd ../myapp
git statusIf you give neither a branch nor -b, the docs say Git names the branch after the last part of the path, and creates it from HEAD if it does not exist.
What does git worktree not allow?
git worktree does not let you check out the same branch in two folders by default. add refuses a branch that is already checked out in another worktree, unless you pass --force.
That refusal protects you from the same branch being changed in two places at once. If you want to see the same code in two places, open it on a new branch or with --detach.
How do you clean up after yourself?
You clean up with git worktree remove, and you see every folder with git worktree list. The docs set these rules:
git worktree listshows the main worktree first, then each linked worktree, with the branch checked out in each.git worktree removeonly removes a clean worktree, with no untracked files and no changes. A dirty one needs--force, and the main worktree cannot be removed.If you deleted the folder by hand,
git worktree pruneremoves its information from the repository.
git worktree list
git worktree remove ../myapp-hotfixWhere do you start now?
The lesson for us as developers: an urgent fix does not have to stop your work, it only needs a second folder.
Try
git worktree addon one of your projects, with a new branch in a folder next to the project.Name the folders after the branch, like
myapp-hotfix, so you always know where you are.When you finish, run
git worktree remove, and now and thengit worktree listto see what you left open.
If the urgent fix itself turns out wrong after you pushed it, we wrote about how to undo a commit after a push. All our developer tools articles are in one place: developer tools articles. And if you are still building your path as a programmer, there is the 2026 programmer roadmap.
How many times last week did you stash just to fix something small on another branch?
FAQ
Does a worktree take a full copy of the repository?
No. According to the Git docs, a new worktree is linked to the same repository and shares everything with it, except per-worktree files such as HEAD and the index.
Can I check out the same branch in two folders?
Not by default. git worktree add refuses a branch that is already checked out in another worktree, unless you use --force, and it is better not to use it for this.
I deleted the worktree folder by hand. What now?
Run git worktree prune. It removes the information of worktrees whose folders are missing, and next time use git worktree remove.


