Created: June 12, 2026
Last updated: June 12, 2026
Switching branches in Git usually requires stashing your changes, committing incomplete work, or cloning a separate copy of the repository. Git worktrees solve this by allowing you to have multiple active branches checked out concurrently in separate directories, all linked to a single database store.
To create a new worktree, specify the folder location and the branch name:
git worktree add ../hotfix-branch-folder origin/mainThis command creates a new directory named hotfix-branch-folder one level up from your repository, checks out the main branch into it, and links it back to the active repository.
To see all folders checked out from the repository, run:
git worktree listThis returns a listing of paths, commit hashes, and checkout branch names:
/home/user/repos/project e714b8a [feature-branch]
/home/user/repos/hotfix-branch-folder 2490ac9 [main]Once you are done with a task and have pushed your commits, you can delete the worktree. Navigate back to your main repository directory and run:
git worktree remove ../hotfix-branch-folderThis command deletes the check-out folder and removes the link from Git's indexing tree, keeping your workspace clean.