| name | repo-setup | ||
|---|---|---|---|
| description | Clone or refresh a GitHub repo and prepare the working tree. Load this before any situation skill. | ||
| license | Apache-2.0 | ||
| metadata |
|
Clone or refresh the repo and create an isolated worktree for the branch.
The main clone at ~/dev/<owner>/<repo> is shared across sessions. Working
directly in it causes concurrent sessions to overwrite each other's changes.
Git worktrees give each branch its own directory with its own working tree
and index, while sharing the object store.
-
Clone (or refresh) the bare-ish main clone:
gh repo clone <owner>/<repo> ~/dev/<owner>/<repo> -- --depth=50 2>/dev/null || true cd ~/dev/<owner>/<repo> git fetch --all --prune
-
Determine the branch name:
- New issue:
issue-<number>-<slug>(e.g.issue-42-fix-login) - Existing PR: the PR's head branch — get it with:
BRANCH=$(gh pr view <number> --json headRefName --jq .headRefName)
- New issue:
-
Create or reuse a worktree for the branch:
WORKTREE=~/dev/<owner>/<repo>-wt/<branch>
- If
$WORKTREEalready exists, verify it's healthy:If that fails, remove and recreate:git -C "$WORKTREE" rev-parse --git-dir >/dev/null 2>&1
Then fall through to the new/existing branch creation below. If healthy,git -C ~/dev/<owner>/<repo> worktree remove "$WORKTREE" --force 2>/dev/null || rm -rf "$WORKTREE"
cd "$WORKTREE", pull the latest, and skip to step 4:git fetch origin git reset --hard "origin/<branch>" 2>/dev/null || true
- New branch (issue):
DEFAULT_BRANCH=$(gh repo view --json defaultBranchRef --jq .defaultBranchRef.name) git worktree add "$WORKTREE" -b <branch> "origin/$DEFAULT_BRANCH"
- Existing branch (PR checkout):
git fetch origin "<branch>:<branch>" 2>/dev/null || true git worktree add "$WORKTREE" "<branch>"
- If
-
Work in the worktree — all subsequent commands run from
$WORKTREE:cd "$WORKTREE"
-
Clean up (optional, after push): if the worktree is no longer needed:
git -C ~/dev/<owner>/<repo> worktree remove "$WORKTREE" --force
- Never
git reset --hardorgit clean -fdin the main clone — other worktrees depend on the shared objects. - The worktree directory pattern
~/dev/<owner>/<repo>-wt/<branch>keeps worktrees adjacent to the main clone without nesting inside it.