git-worktree

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Git Worktree Manager

Git Worktree 管理器

Manage repositories using git worktrees. This allows working on multiple branches simultaneously without switching or stashing.
使用Git worktree管理仓库。这允许你同时处理多个分支,无需切换分支或暂存更改。

Concept

概念

~/dev/personal/auto/
├── my-project/              # Main clone (bare or with default branch)
│   └── .git/
└── my-project-worktrees/    # Worktrees directory
    ├── feature-123/         # Worktree for feature branch
    ├── feature-456/         # Another feature branch
    └── hotfix-789/          # Hotfix branch
~/dev/personal/auto/
├── my-project/              # 主克隆仓库(裸仓库或带有默认分支)
│   └── .git/
└── my-project-worktrees/    # Worktree 目录
    ├── feature-123/         # 功能分支对应的Worktree
    ├── feature-456/         # 另一个功能分支
    └── hotfix-789/          # 热修复分支

Quick Reference

快速参考

ActionScript
Clone repo
scripts/clone_repo.sh <repo_url> [name]
Create worktree
scripts/create_worktree.sh <repo_name> <branch_name>
List worktrees
scripts/list_worktrees.sh <repo_name>
Remove worktree
scripts/remove_worktree.sh <repo_name> <branch_name>
操作脚本
克隆仓库
scripts/clone_repo.sh <repo_url> [name]
创建Worktree
scripts/create_worktree.sh <repo_name> <branch_name>
列出Worktree
scripts/list_worktrees.sh <repo_name>
删除Worktree
scripts/remove_worktree.sh <repo_name> <branch_name>

Workflow Examples

工作流示例

Start working on a JIRA ticket

开始处理JIRA工单

bash
undefined
bash
undefined

Clone if not already done

若未克隆则执行克隆

./scripts/clone_repo.sh https://github.com/org/my-app.git
./scripts/clone_repo.sh https://github.com/org/my-app.git

Create worktree for ticket

为工单创建Worktree

./scripts/create_worktree.sh my-app PROJ-123-new-feature
./scripts/create_worktree.sh my-app PROJ-123-new-feature

Work in the worktree directory

进入Worktree目录开展工作

cd ~/dev/personal/auto/my-app-worktrees/PROJ-123-new-feature
undefined
cd ~/dev/personal/auto/my-app-worktrees/PROJ-123-new-feature
undefined

Clean up after PR merged

PR合并后清理

bash
./scripts/remove_worktree.sh my-app PROJ-123-new-feature
bash
./scripts/remove_worktree.sh my-app PROJ-123-new-feature

Integration

集成

Uses
workspace-manager
to determine the work directory. Repositories are cloned to
<workspace_path>/<repo_name>/
and worktrees are created in
<workspace_path>/<repo_name>-worktrees/
.
使用
workspace-manager
确定工作目录。仓库会被克隆到
<workspace_path>/<repo_name>/
,Worktree则创建在
<workspace_path>/<repo_name>-worktrees/
目录下。