← 返回
未分类 中文

Git Repo

Git repository and SourceGit integration. Topics — clone (ghq get + auto SourceGit register), fix-worktree (bare repo recovery), merge-duplicate (same-origin...
Git 仓库与 SourceGit 集成:克隆(ghq get + 自动注册 SourceGit),修复工作树(裸仓库恢复),合并重复(同源处理)
drumrobot drumrobot 来源
未分类 clawhub v0.3.2 4 版本 100000 Key: 无需
★ 0
Stars
📥 582
下载
💾 1
安装
4
版本
#latest

概述

Git Repo

Git repository management and SourceGit GUI client integration.

Topics

TopicDescriptionGuide
---------------------------
cloneghq get with automatic SourceGit registration (multi-account support)clone.md
fix-worktreebare repo worktree configuration recoveryfix-worktree.md
merge-duplicatemerge duplicate repositories with the same originmerge-duplicate.md
migratemigrate regular Git repositories to ghq directory structuremigrate.md
move-worktreemove/register unregistered worktrees to .claude/worktrees/, reclaim merged PR worktreesmove-worktree.md
patrolbatch inspection of ghq repositories (status, stash, unpushed + commit-splitter integration)patrol.md
rename-worktreerename worktree directory and metadata (cross-platform, Windows safe)rename-worktree.md
sourcegitSourceGit preference.json management (add repos, workspaces, folder rename)sourcegit.md
ssh-keyper-repo SSH key mapping for multi-account GitHub (core.sshCommand + IdentityAgent)ssh-key.md
worktreeunified worktree acquisition: inventory, reuse inactive, or create new at .claude/worktrees/worktree.md

Topic Dependencies

worktree (entry point — inventory + decision)
  └─→ rename-worktree (reuse registered worktree)
  └─→ move-worktree (register unregistered or relocate)

Worktree decision tree (HARD STOP — every time a worktree is needed)

Whenever a worktree is needed (plan/build/test without switching branches, PR verification, isolated work environment, new commit while main branch has another in-flight task), check for inactive worktree reuse before creating a new one.

Flow

  1. git -C worktree list to enumerate existing worktrees
  2. Identify inactive candidates:
    • Merged-PR worktrees (commit hash equals the base branch's merge commit)
    • Stale fix/refactor branch worktrees (confirm with the user)
  3. If an inactive worktree exists → reuse via the rename-worktree topic (rename the directory + metadata, switch branch)
  4. If no inactive worktree exists or the user opts for new → git worktree add

New-commit-start trigger (HARD STOP — paired with git.md)

When committing new work on a main/master/develop branch, if git status shows uncommitted changes from another task, worktree splitting is mandatory.

Entry conditions (any one)

  • Current branch = main/master/develop
  • git status shows 1+ changed files outside the new work (e.g., another task's unstaged files)
  • Unpushed commits include another task's work

Decision tree on entry

git status (check for other changes)
  ├─ 0 other changes, branch = PR/feature → commit in place
  ├─ 0 other changes, branch = main/master/develop
  │    → AskUserQuestion: (a) create PR branch from current (b) create PR branch in a new worktree
  ├─ 1+ other changes, branch = main/master/develop
  │    → worktree split required. Leave other changes in place, isolate new work in a new worktree
  └─ Another task running on a PR branch with stray changes on main
       → Report to the user (confirm intent of stray changes) → decide worktree split + stray cleanup

Worktree split procedure

  1. Leave the new work's diff in place — do NOT stash (preserve the working directory)
  2. git -C worktree list to inspect inactive worktrees (per the decision tree above)
  3. Inactive candidate present → reuse via rename-worktree; otherwise git -C worktree add .claude/worktrees/ (or the worktree path defined by the active environment context — see worktree.md "Default Path Rules")
  4. cd into the new worktree, then git checkout -b (or use the existing inactive branch)
  5. Re-apply the same diff in the new worktree via Edit (the original main changes stay on main)
  6. add → commit → push → PR inside the new worktree

Don't / Do

#Don'tDo
---------------
1main has other changes; add the new file + commit + push anywayRun git status → if other changes exist → split into a worktree → commit in the new worktree
2Hide other changes with git stash and commit on mainstash breaks the other task's intent/sequence. Worktree split is safer
3Assume "my changes only — no conflict"Other working-directory changes can spill over (tests, builds, IDE state)
4Omit "worktree split" from the AskUserQuestion commit optionsIf branch is main/master/develop and other changes exist, "split into worktree + create PR branch" must be the first option

Don't / Do

#Don'tDo
---------------
1Default to git worktree add whenever a worktree is neededgit worktree list first → check inactive candidates → consider rename-worktree
2"Temporary verification — create new and delete" pattern (wastes resources)Reuse a merged-PR worktree (e.g., one stuck at the merge commit) via rename
3AskUserQuestion options offer only "create new worktree"Include "reuse an existing worktree by rename" whenever an inactive worktree exists
4Decide on the worktree autonomously before asking the userWhen inactive candidates exist, ask which one to reuse
5Ignore merged-PR worktreesReclaim them with move-worktree or rename-worktree
6Place "create new worktree" as option 1/Recommended when inactive candidates existReuse is Recommended/option 1. New is option 2 or below
7"Unknown purpose for the inactive candidate → recommend safe new" thinkingInspect the inactive candidate state (git log, git status) first. If still ambiguous, ask the user which to reuse — but keep reuse as option 1

Recommended placement rule (HARD STOP — prevent 2nd recurrence)

When building AskUserQuestion options for worktree selection:

Inactive candidatesOption order + Recommended
--------------------------------------
0Option 1: New worktree (Recommended). Option 2: Hold
1Option 1: Reuse inactive by rename (Recommended). Option 2: New worktree. Option 3: Hold
2+Option 1: Rename inactive A (Recommended). Option 2: Rename inactive B. Option 3: New worktree. Option 4: Hold

The Recommended marker must attach to the reuse option. "Safer to default to new because purpose is unclear" is an autonomous judgment — instead, document the "verify current commit/branch before reuse" procedure in the rename option description so the user can decide.

Self-check (before any worktree work)

  1. Did you call git -C worktree list?
  2. Does any worktree in the output match (a) the same commit as HEAD or (b) a merge commit hash? → inactive candidate
  3. If inactive candidates exist, include both the new-add option and the reuse option in AskUserQuestion
  4. Is the Recommended marker attached to the reuse option? (apply the "Recommended placement rule" table)
  5. Use new-add only when 0 inactive candidates exist OR the user explicitly chose new

Typical failure mode

When a worktree is needed for plan verification, defaulting to "create new + remove later" wastes resources. git worktree list often shows merged-PR worktrees stuck on the merge commit hash — these are reuse candidates. Always inventory first before creating a new worktree.

Quick Reference

ghq Clone (automatic SourceGit registration)

When ghq get is executed, the following happens automatically:

  1. Clone the repository
  2. Register in SourceGit (under the appropriate group)
  3. Auto-create the group if it doesn't exist

Proceeds automatically without user confirmation

Detailed guide

SourceGit Management

Directly edit the SourceGit GUI client's configuration file to add repositories, create workspaces, rename folders, etc.

Key features:

  • Add/remove repositories
  • Create workspaces
  • Sync ghq repositories
  • Update paths on folder rename

Detailed guide

ghq Migration

Migrate regular Git repositories to ghq directory structure (~/ghq/host/group/repo/).

Key features:

  • Automatic bare+worktree structure conversion
  • Create symbolic links at original location
  • Nested group support (host/group/subgroup/repo)

Detailed guide

Repo Patrol (batch inspection)

Batch inspect and clean up the status of repositories under ghq.

Key features:

  • Parallel collection of status, stash, unpushed for all repositories
  • Status-based processing (commit-splitter integration, stash pop, push)
  • Optional fetch all at the end

Detailed guide

Common Workflow

  1. Repository migration: Migrate to ghq structure with migrate topic
  2. SourceGit update: Register new paths with sourcegit topic
  3. Batch inspection: Clean up uncommitted/unpushed changes with patrol topic

Scripts

  • ./scripts/repo-to-ghq.sh - Script to move repositories to ghq path

版本历史

共 4 个版本

  • v0.3.2 当前
    2026-06-09 17:27
  • v0.3.1
    2026-06-04 13:15
  • v0.3.0
    2026-05-28 13:13
  • v0.1.2
    2026-05-03 10:18 安全 安全

安全检测

腾讯云安全 (Keen)

队列中

腾讯云安全 (Sanbu)

队列中

🔗 相关推荐

Commit Tidy

drumrobot
分析暂存/已提交变更,推荐拆分或压缩策略;interactive-amend - 基于工作树的 amend+rebase 循环,用于处理领先于 HEA 的提交...
★ 1 📥 585

Claude Session

drumrobot
Claude Code session management. Topics — id (current session UUID), list (enumerate sessions), search (keyword + result
★ 0 📥 659

Tdd

drumrobot
用于编码和缺陷修复的测试驱动开发(TDD),包括 Red→Green→Refactor 循环、预期行为定义、缺陷修复 TDD、反模式 [cycle.md]、运行...
★ 0 📥 1,173