Git Worktrees

Git Worktrees

Created: June 12, 2026

Last updated: June 12, 2026

Git Worktrees

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.


1. The Core Benefits

  • Zero Stash Overhead: Switch to another branch without interrupting your active, uncommitted work.
  • Shared Repository Database: Unlike multiple clones, all worktrees share the same local git configuration, fetch objects, and remote branches.
  • Fast Hotfixes: Instantly open a new folder, fix a bug on main, push, and return to your feature work.

2. Managing Worktrees

Adding a Worktree

To create a new worktree, specify the folder location and the branch name:

git worktree add ../hotfix-branch-folder origin/main

This 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.

Listing Active Worktrees

To see all folders checked out from the repository, run:

git worktree list

This 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]

3. Cleaning Up

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-folder

This command deletes the check-out folder and removes the link from Git's indexing tree, keeping your workspace clean.