DEV Community

Cover image for How to Have Multiple Branches Checked Out at the Same Time?
bright inventions
bright inventions

Posted on • Originally published at brightinventions.pl

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.

What is a Git worktree?


A git 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 worktreeis 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.


Why you should use worktree to simultaneously check your branches?


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 git stash, git 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!


By Piotr Mionskowski, Partner, Team Leader, Technology Evangelist @ Bright Inventions

Top comments (0)