如何使用TortoiseGit创建Git工作树(worktree)?含UI操作指引
Hey folks, let's walk through exactly how to create a Git worktree using TortoiseGit—covering both the command-line approach and the full UI method since you asked about both scenarios.
1. Creating a Git Worktree with TortoiseGit via Command Line
If you prefer using commands but still want to leverage TortoiseGit's configured environment, here's how to do it:
- First, ensure you have both Git and TortoiseGit installed and set up correctly on your system.
- Open TortoiseGit Bash—you can find this in your Start Menu, or right-click any folder and select it from the context menu.
- Navigate to your existing Git repository using the
cdcommand, for example:cd C:\Code\MyMainRepository - Run the standard Git worktree creation command:
git worktree add <path-to-new-worktree> <branch-name>- Example:
git worktree add ../MyBugFixWorktree hotfix/login-bugwill create a new worktree in the parent directory, tied directly to thehotfix/login-bugbranch.
- Example:
- Once the command finishes, you can use all of TortoiseGit's familiar UI tools (commit, push, pull, etc.) on this new worktree just like your main repository.
2. Creating a Git Worktree via TortoiseGit's UI Interface
For a fully graphical workflow (no command line needed), follow these steps:
- Open File Explorer and navigate to your existing Git repository folder.
- Right-click anywhere inside the repo folder to bring up the TortoiseGit context menu.
- Hover over the Git Worktree option (it’s near the top of the menu in recent TortoiseGit versions).
- Select Add... from the submenu to open the "Add Worktree" dialog.
- Fill in the required fields in the dialog:
- Path: Enter or browse to the absolute path where you want the new worktree to live. This folder shouldn’t exist yet—Git will create it for you automatically.
- Branch: Pick an existing branch from the dropdown, or type in a new branch name (TortoiseGit will create the branch if it doesn’t exist).
- Optional: Check the Create branch box if you’re using a new branch name, and set an upstream branch if needed for pushing/pulling.
- Click OK to start the process. TortoiseGit will run all the necessary Git commands in the background to set up your worktree.
- Once complete, head to the new worktree folder—you can use TortoiseGit’s UI tools here exactly like you do with your main repo.
Quick Notes
- Always delete worktrees using TortoiseGit’s Git Worktree > Delete option (don’t just delete the folder manually)—this cleans up metadata in your main repo properly.
- Worktree support was added in TortoiseGit version 2.8.0, so make sure you’re running an up-to-date version if you don’t see the option.
内容的提问来源于stack exchange,提问作者Bill Church
相关产品推荐
相关产品推荐

