%% date:: [[2023-05-06]] parent:: [[Git]], [[GitHub]] %% # [[Worktrees in Git]] Worktrees in [[Git]] allow you to have multiple checked out branches of the same repository at the same time, so that you can work on them concurrently instead of stashing and unstashing changes. [^pulec] Each worktree is both a subdirectory and a branch of the repo, and multiple worktrees can be worked on concurrently. ## Why would you use worktrees? If you're working on something, have uncommitted changes, and then suddenly need to work on something else, a common strategy would be to [[Stashing in Git|stash]] your changes, make the urgent changes and push them, and then unstash the initial changes you had made. However, this process is a little finicky and can lead to you accidentally stashing changes. Worktrees are an alternative to this process: they create a new subdirectory with a copy of the repo and a new branch of the repo. ## Usage ### Adding a worktree ``` git worktree add <worktree_name> ``` This creates a subdirectory called `<worktree_name>`. [^pulec]: Pulec, J. (2020). *Git Worktrees: The best Git feature you've never heard of.* Retrieved from https://levelup.gitconnected.com/git-worktrees-the-best-git-feature-youve-never-heard-of-9cd21df67baf