Git Worktree: Enhance Your Git Workflow Have you ever been in the middle of coding a feature, and out of nowhere you get a notification that production is down? If you’re using Git, you now have a few options: commit your work, stash your work, or discard your work. All these come with their problems depending on the situation. If you commit half-baked code, you may want to come back later and rebase to clean up your commit history. Stashing can cause problems because what if you need to stash extra code later before switching back to your original feature work? I’ll throw away my current changes if they’re small, but otherwise, no thanks. I recently stumbled upon , and it has been an amazing boost in my productivity. Git worktree What Is Git Worktree? Git worktree allows us to check out many branches in a git repository. This lets us switch between different branches in a Git repository without losing our non-committed work. Git does this by creating new, separate directories called a “linked worktree” that gets associated with a single “main worktree” (the directory created using or ). git clone git init To checkout a new worktree, we use the command: . Worktrees get created as new directories. We give the add command a path to where we want the new directory created and which git branch we want to checkout. worktree add git worktree add <path> <branch_name> Like , we can create brand new branches by adding the argument ( ). git checkout -b -b git worktree add -b <branch_name> <path> We can see all the worktrees we’ve created using the command. git worktree list With our different linked worktrees created, we can change code and switch between isolated instances of our codebase. The changes done in one worktree do not affect the other worktrees. What about if we want to commit and push our changes out to Github? No problem! Git worktree is a way to check out many branches. So, once we’re done making changes in our worktree, we can , , and like if we are working on a different branch. git add git commit git push origin The changes would show up on Github under the we gave in . <branch_name> git worktree add <path> <branch_name> When we are done with a worktree, we can call to delete it. git worktree remove <path_to_worktree> End I keep all worktrees in a separate directory , outside of my general projects directory , to reduce clutter and keep “main worktrees” explicit from “linked worktrees”. ~/.worktree ~/projects I am constantly switching between branches and code, and Git worktree has been a huge help to my workflow!