Yes you can stop juggling checkouts like a circus act. With git worktree you can have multiple worktrees so different branches live in different folders and you never accidentally commit to the wrong branch again. This is pure developer hygiene and a tiny rebellion against endless context switching in the CLI.
Before you summon extra worktrees make sure your repository is clean and the branch you want exists or can be created. Use the familiar Git commands in the repo root to avoid surprises.
git status
git branch feature-branch
or create it from a commit or remote when you add the worktreeAdding a worktree is basically asking Git to give you a sibling folder with its own checkout. It links back to the same repository so you do not need another clone and you keep objects shared on disk.
git worktree add ../feature-branch feature-branch
That example creates a folder next to your current repo named ../feature-branch
and checks out the branch called feature-branch
there. If the branch does not exist and you created it earlier Git will use it. If you create it on the fly Git will place the branch in the new worktree.
Use the worktree just like a normal checkout. Run git status
and git commit
inside the worktree folder. Branch operations behave the same as in a clone. The main difference is that the main repo and the worktree are separate checkouts so you can keep one for an integration branch and another for a quick fix or experimental feature.
When you are done remove the linked checkout so Git does not keep stale metadata around. If the branch is no longer needed delete or merge it so it does not become an orphan.
git worktree remove ../feature-branch
# then optionally
git worktree prune
git worktree prune
removes stale references to worktrees that are gone. Remember to delete or merge branches you no longer need to keep the repository tidy.
Multiple worktrees speed up multitasking because you can keep context for each branch in its own folder. That reduces accidental commits on the wrong branch and makes parallel development with Git less painful. Go forth and branch responsibly.
I know how you can get Azure Certified, Google Cloud Certified and AWS Certified. It's a cool certification exam simulator site called certificationexams.pro. Check it out, and tell them Cameron sent ya!
This is a dedicated watch page for a single video.