How to Have Multiple Branches Checked Out at the Same Time?
Find out how to use Git worktree to have multiple branches checked out at a time.
worktree is a linked copy of your Git repository, allowing you to have multiple branches checked out at a time. A
worktree has a separate path from your main working copy, but it can be in a different state and on a different branch.
Git worktree is an alternative to
git stash. Both of these mechanisms help you to manage multiple streams of work at once. The basic approach is to git-stash your changes and check out the other branch.
The specifics of
worktree approach is that it operates within a single
worktree. Stashing the changes, and checking out the branch can cause performance mayhem within your IDE, which needs to reindex the files and that can take time in bigger projects.
It is a great way to switch to a different branch for a brief moment but is unsuitable in more complex situations.
As opposed to
worktree parallelizes your work by creating dedicated work trees and placing them in separate folders.
Each tree/folder is separately managed by a dedicated IDE window.
I hope you enjoyed this bright dev tip!