Original Note

进入主仓库

  • self_study_notes
  • Original Note
  • Updated: unknown
Source Collection
self_study_notes
Source Path
self_study_notes/git/worktree使用.md
Type
Original Note
Updated At
unknown
cd ~/project
# 进入主仓库

git worktree add ../project-agent1 -b agent1 main
# 基于 main 创建 agent1 分支和独立 worktree

cd ../project-agent1
# 进入 Agent 1 工作目录

git status
# 检查当前分支和修改状态

git add .
# 暂存所有修改

git commit -m "feat: xxx"
# 提交 Agent 1 的修改

cd ~/project
# 回到主仓库

git merge agent1
# 将 agent1 合并到 main

git worktree remove ../project-agent1
# 删除 Agent 1 的 worktree

git branch -d agent1
# 删除已合并的 agent1 分支

worktree默认不会复制被 .gitignore 忽略的文件。 如果需要完全同步,则使用

git worktree add ../project-agent1 -b agent1 main
# 基于 main 创建 agent1 分支和独立 worktree

rsync -a --ignore-existing --exclude='.git' ~/project/ ~/project-agent1/
# 只复制 agent1 中不存在的文件,已有文件直接跳过
# 同步主仓库全部文件,但不删除 Agent 目录已有的额外文件

Evidence-backed relations

Source Note · Same Topic

切换到中文