GitWorktree.org logoGitWorktree.org

Git Worktree Tutorial

Git worktree lets you check out multiple branches of the same repository into separate directories simultaneously. Instead of stashing changes or cloning the repo again, you create a linked worktree and work on a different branch in parallel. This tutorial covers every git worktree subcommand with real-world examples so you can start using worktrees in your daily workflow.

Prerequisites

Git worktree was introduced in Git 2.5 (released July 2015). Verify your version before getting started:

git --version

If your version is below 2.5, upgrade Git using your system package manager. Some subcommands like git worktree move and git worktree lock require Git 2.17+.

Upgrade Git
# macOS (Homebrew)
brew install git

# Ubuntu / Debian
sudo apt-get install git

# Windows (winget)
winget install Git.Git

Quick Start

Here is how to use git worktree in three commands. From inside any Git repository:

Worktree in 30 seconds
# 1. Create a new worktree for a feature branch
git worktree add ../feature-login feature/login

# 2. Work in the new directory
cd ../feature-login

# 3. When finished, remove it
git worktree remove ../feature-login

Commands

Each subcommand is covered in detail on its own page. Click through for full syntax, flags, and examples.

How Git Worktrees Work Under the Hood

Every Git repository has a main worktree (the directory where you ran git init or git clone) and can have zero or more linked worktrees. All worktrees share the same .git/objects store, refs, and configuration. This means:

  • No extra disk space for duplicated object data.
  • Commits, tags, and stashes are visible from every worktree.
  • Each worktree has its own index (staging area) and HEAD, so operations in one worktree do not affect another.
  • A branch can only be checked out in one worktree at a time to prevent conflicting changes.
Worktree internals
# Linked worktrees store a .git *file* (not a directory)
cat ../feature-login/.git
# gitdir: /path/to/main-repo/.git/worktrees/feature-login

Next Steps

Start with git worktree add to create your first linked worktree. When you are done with a worktree, head to git worktree remove to learn how to clean up properly. For a quick-reference card, see the home page.