Skip to content

Git Worktree vs Git Clone: Which Should You Use for Multiple Branches?

I needed to work on three different branches at the same time. One for a hotfix, one for a feature, and one for code review. I had two choices: clone the repository three times, or use git worktree. I tested both approaches and found a clear winner.

The Problem with Multiple Clones

Most developers solve this problem by cloning the same repository multiple times. Each clone gets its own folder and its own .git directory.

Multiple clones approach
# Clone for main work
git clone https://github.com/company/project.git project-main
# Clone for feature branch
git clone https://github.com/company/project.git project-feature
# Clone for hotfix
git clone https://github.com/company/project.git project-hotfix

This works, but it wastes disk space. Each .git directory contains the full repository history, all branches, and all objects. For a 500 MB repository, three clones mean 1.5 GB on disk.

There’s another problem. When you push changes from one clone, the other clones don’t know about it. You must run git fetch in each clone to stay synchronized.

The Git Worktree Solution

Git worktree lets you check out multiple branches into separate directories while sharing a single .git directory.

Git worktree approach
# Clone once
git clone https://github.com/company/project.git
cd project
# Create worktrees for different branches
git worktree add ../project-feature feature/new-auth
git worktree add ../project-hotfix hotfix/login-bug

Each worktree is a working directory with its own checked-out branch. But they all share the same Git database. For that same 500 MB repository, three worktrees use about 600 MB total—the original 500 MB plus 100 MB for the extra working trees.

Disk Space Comparison

I ran a real test on a mid-sized repository. Here are the results:

Disk usage comparison
# Three separate clones
du -sh project-main project-feature project-hotfix
# 520M project-main
# 520M project-feature
# 520M project-hotfix
# Total: 1.56 GB
# One clone with two worktrees
du -sh project project-feature project-hotfix
# 520M project (includes shared .git)
# 85M project-feature (working tree only)
# 85M project-hotfix (working tree only)
# Total: 690 MB

Worktrees saved 870 MB in this test. The savings grow larger with bigger repositories and more branches.

Synchronization Benefits

Worktrees share the same Git refs. When you run git fetch in any worktree, all worktrees see the new commits.

Synchronization example
# In project-feature worktree
cd ../project-feature
git pull origin main
# This updates refs for ALL worktrees
cd ../project
git log --oneline -3 # Shows the same updated history

With separate clones, you’d need to run git pull in each clone individually.

Comparison Summary

FeatureGit WorktreeGit Clone
Disk SpaceMinimal (shared .git)Full per clone
Sync SpeedInstant (same repo)Requires fetch per clone
IsolationShared refsComplete
Branch SwitchingInstant (separate dirs)Requires stash/commit
Best ForSame project branchesSeparate projects

When to Use Each Approach

Use git worktree when:

  • Working on multiple branches of the same project
  • Switching between branches frequently
  • Disk space matters
  • You want automatic synchronization

Use git clone when:

  • Working on completely separate projects
  • You need total isolation (no shared refs)
  • Testing with different Git configurations
  • Contributing to forks you don’t control

Quick Reference Commands

Common worktree commands
# List all worktrees
git worktree list
# Add a new worktree for a branch
git worktree add <path> <branch>
# Add worktree and create new branch
git worktree add -b <new-branch> <path>
# Remove a worktree
git worktree remove <path>
# Prune deleted worktrees
git worktree prune

Summary

Git worktree is the better choice for working on multiple branches of the same repository. It saves disk space, keeps branches synchronized, and simplifies repository management. Use git clone only when you need complete isolation between different projects or forks.

The command is simple. The benefits are immediate. Next time you need to work on multiple branches, try git worktree add instead of cloning again.

Final Words + More Resources

My intention with this article was to help others share my knowledge and experience. If you want to contact me, you can contact by email: Email me

Here are also the most important links from this article along with some further resources that will help you in this scope:

Oh, and if you found these resources useful, don’t forget to support me by starring the repo on GitHub!

Comments