https://daleseo.com/git-worktree/
Other commands#
git worktree has several more commands. This section introduces a few commands that are useful in practice.
Advanced git worktree add#
In the example above, a worktree was created simply with git worktree add <path>, but you can also specify a particular branch or provide the name of a new branch.
Use git worktree add <path> <branch> to create a worktree that uses an existing branch.
Use git worktree add <path> -b <branch> to create a worktree and create a new branch with the specified name at the same time.
Use git worktree add <path> <commit-ish> to create a worktree from a specific commit instead of the current HEAD commit.
git worktree list#
Use git worktree list to see the list of currently created worktrees, their branch names, and their state.
❯ git worktree list /Users/sample/Development/project cbfc60b [main] /Users/sample/Development/project-hotfix cbfc60b [project-hotfix] prunable You can check each worktree path, the commit it currently points to, the branch it uses, and related state.
git worktree remove#
git worktree remove is a command for deleting a worktree that is no longer needed.
❯ git worktree remove project-hotfix ❯ git worktree list /Users/sample/Development/project cbfc60b [main] Enter the name or path of the worktree you want to remove, and the worktree will be deleted. The branch itself is not deleted.