Blog of Suresh Kumar Nalluru

10 Feb 2021

Git Worktree

Use the same git repo and .git content but have multiple working directories. This can be very useful if you are switcing contexts on the same monorepo.

From the documentation explaining the use-case:

create a temporary linked working tree to make the emergency fix, remove it when done, and then resume your earlier refactoring session.

1$ git worktree add -b emergency-fix ../temp master
2$ pushd ../temp
3# ... hack hack hack ...
4$ git commit -a -m 'emergency fix for boss'
5$ popd
6$ git worktree remove ../temp