← 返回命令列表

Linux command

git-worktree 命令

安全

权限或系统影响较大,执行前请核对目标。

常用示例

Add worktree

git worktree add [../feature-branch] [branch-name]

List worktrees

git worktree list

Remove worktree

git worktree remove [path]

Prune stale worktrees

git worktree prune

Add worktree for new branch

git worktree add -b [new-branch] [path]

说明

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.

参数

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.

FAQ

What is the git-worktree command used for?

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.

How do I run a basic git-worktree example?

Run `git worktree add [../feature-branch] [branch-name]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.

What does add _PATH_ _BRANCH_ do in git-worktree?

Add new worktree.