LinuxCommandLibrary

git-worktree

Manage multiple working trees for a repository

TLDR

Add worktree

$ git worktree add [../feature-branch] [branch-name]
copy
List worktrees
$ git worktree list
copy
Remove worktree
$ git worktree remove [path]
copy
Prune stale worktrees
$ git worktree prune
copy
Add worktree for new branch
$ git worktree add -b [new-branch] [path]
copy

SYNOPSIS

git worktree command [options]

DESCRIPTION

git worktree manages multiple working trees attached to one repository. Each worktree can have a different branch checked out, enabling parallel work without stashing or switching branches.
Worktrees share the same repository data but have separate working directories. This is useful for working on a bug fix while a feature branch is mid-development, or for running tests on one branch while editing another.

PARAMETERS

add PATH BRANCH

Add new worktree.
list
List worktrees.
remove PATH
Remove worktree.
prune
Remove stale worktrees.
-b BRANCH
Create new branch.
--help
Display help information.

CAVEATS

Same branch can't be checked out twice. Worktrees share reflog. Removing worktree doesn't delete branch.

HISTORY

git worktree was added in Git 2.5 to enable multiple working directories from a single repository clone.

SEE ALSO

> TERMINAL_GEAR

Curated for the Linux community

Copied to clipboard

> TERMINAL_GEAR

Curated for the Linux community