
Harness Worktrees
- 1 installs
- 1 repo stars
- Updated July 30, 2026
- aojdevstudio/agentic-utilities
Harness-worktrees is a Claude Code skill that resets a parallel git worktree to latest origin/main while keeping its branch identity.
About
Harness-worktrees is a Claude Code skill for maintaining Superconductor/pi parallel git worktrees. A developer uses it to reset, refresh, or sync the current worktree to latest origin/main after a PR merges, without switching to main. Its 'Mode C' fetches origin and resets the current branch to origin/main while preserving the worktree's branch identity, and it refuses dirty worktrees unless stashing is requested.
- 'Mode C' resets the current worktree to origin/main while preserving its branch identity
- Refuses dirty worktrees unless --stash is passed
- Avoids git switch main because main may be checked out in another worktree
Harness Worktrees by the numbers
- 1 all-time installs (skills.sh)
- Ranked #527 of 733 Git & Pull Requests skills by installs in the Skillselion catalog
- Data as of Jul 31, 2026 (Skillselion catalog sync)
harness-worktrees capabilities & compatibility
- Capabilities
- harness worktrees · gitworkflow
- Use cases
- ci cd
What harness-worktrees says it does
Manage Superconductor/pi parallel git worktrees.
The reset script refuses dirty worktrees unless `--stash` is passed.
npx skills add https://github.com/aojdevstudio/agentic-utilities --skill harness-worktreesAdd your badge
Show developers this skill is listed on Skillselion. Paste this into your README.
| Installs | 1 |
|---|---|
| repo stars | ★ 1 |
| Last updated | July 30, 2026 |
| Repository | aojdevstudio/agentic-utilities ↗ |
What it does
Reset the current git worktree to latest origin/main after a PR merges without switching to main.
Who is it for?
Getting a per-harness worktree current with main after a PR merges.
Skip if: Single-worktree repos where git switch main and pull works fine.
When should I use this skill?
The user says 'mode C', 'get current with main', or 'reset this worktree to main'.
What you get
The current branch points at latest origin/main with ahead 0, behind 0, and a clean worktree.
By the numbers
- single reset-worktree-to-main.sh script
- requires --stash for dirty worktrees
Files
Harness Worktrees for Pi
Pi-native worktree maintenance for repos that use one git worktree per coding harness.
Mode C: get this worktree current with main
When the user says any of these, treat it as an explicit instruction to make the current worktree match latest origin/main:
- "mode C"
- "get current with me"
- "get this worktree current"
- "reset this worktree to main"
- "refresh this worktree from main"
- "sync this worktree with latest main"
- "after merge, make this worktree current"
- "update this worktree after my PR merged"
Do not only acknowledge. Do not stop at dry-run. Do not ask for another confirmation for a clean worktree, even if the branch is ahead or behind.
Run the reset directly:
~/.pi/agent/skills/harness-worktrees/scripts/reset-worktree-to-main.sh --confirmThen verify sync:
~/.pi/agent/skills/harness-worktrees/scripts/reset-worktree-to-main.shReport only the useful facts: branch, HEAD, ahead count, behind count, dirty status.
Status-only check
If the user asks whether the worktree is behind, ahead, dirty, or in sync — without asking to get current — run dry-run only:
~/.pi/agent/skills/harness-worktrees/scripts/reset-worktree-to-main.shWhy this is not git switch main && git pull
In a multi-worktree setup, main may already be checked out in another worktree. git switch main can fail or violate ownership expectations.
The safe operation is:
1. stay on the current worktree branch; 2. fetch origin; 3. reset the current branch to origin/main.
This makes the worktree contents match latest main while preserving the worktree's branch identity.
Dirty worktrees
The reset script refuses dirty worktrees unless --stash is passed.
For normal Mode C, run --confirm first. If it aborts because the worktree is dirty, report the dirty files and ask whether to preserve them with:
~/.pi/agent/skills/harness-worktrees/scripts/reset-worktree-to-main.sh --confirm --stashOnly use --stash when the user explicitly asks to preserve/stash local changes.
Safety rules
- Do not switch to
main. - Do not force-push.
- Do not delete branches.
- Do not run
git reset --hardmanually for this workflow; use the script. - For Mode C / get-current requests on a clean worktree, execute
--confirmimmediately. - Refuse dirty worktrees unless the user explicitly asks to stash.
- Branch-local commits may be discarded by Mode C; that is expected when the user explicitly asks to get current with main.
Expected result
The current branch points at latest origin/main; ahead is 0, behind is 0, and the worktree is clean.
#!/usr/bin/env bash
set -euo pipefail
REMOTE="origin"
BRANCH="main"
CONFIRM=0
STASH=0
usage() {
cat <<'USAGE'
reset-worktree-to-main.sh — reset the current git worktree branch to latest origin/main
Dry-run by default. This intentionally does not switch to main, because main may
be checked out in another worktree. It resets the current branch to origin/main.
Usage:
reset-worktree-to-main.sh [--remote origin] [--branch main]
reset-worktree-to-main.sh --confirm [--remote origin] [--branch main]
reset-worktree-to-main.sh --confirm --stash [--remote origin] [--branch main]
Options:
--confirm Execute the reset. Without this flag, only prints a plan.
--stash Before reset, stash tracked + untracked local changes.
Requires --confirm. Without --stash, dirty trees abort.
--remote NAME Remote to fetch/reset from. Default: origin.
--branch NAME Branch on the remote to reset to. Default: main.
-h, --help Show this help.
Safety:
- Refuses to run outside a git worktree.
- Refuses detached HEAD.
- Refuses dirty worktrees unless --stash is passed.
- Never force-pushes or deletes remote branches.
USAGE
}
while [[ $# -gt 0 ]]; do
case "$1" in
--confirm)
CONFIRM=1
shift
;;
--stash)
STASH=1
shift
;;
--remote)
REMOTE="${2:-}"
if [[ -z "$REMOTE" ]]; then
echo "ERROR: --remote requires a value" >&2
exit 2
fi
shift 2
;;
--branch)
BRANCH="${2:-}"
if [[ -z "$BRANCH" ]]; then
echo "ERROR: --branch requires a value" >&2
exit 2
fi
shift 2
;;
-h|--help)
usage
exit 0
;;
*)
echo "ERROR: unknown argument: $1" >&2
usage >&2
exit 2
;;
esac
done
if [[ "$STASH" -eq 1 && "$CONFIRM" -ne 1 ]]; then
echo "ERROR: --stash requires --confirm" >&2
exit 2
fi
if ! git rev-parse --is-inside-work-tree >/dev/null 2>&1; then
echo "ERROR: not inside a git worktree" >&2
exit 2
fi
REPO_ROOT="$(git rev-parse --show-toplevel)"
cd "$REPO_ROOT"
CURRENT_BRANCH="$(git branch --show-current)"
if [[ -z "$CURRENT_BRANCH" ]]; then
echo "ERROR: detached HEAD. Check out a branch before resetting this worktree." >&2
exit 2
fi
if ! git remote get-url "$REMOTE" >/dev/null 2>&1; then
echo "ERROR: remote '$REMOTE' does not exist" >&2
exit 2
fi
TARGET_REF="$REMOTE/$BRANCH"
echo "Fetching $REMOTE ..."
git fetch "$REMOTE" --prune >/dev/null
if ! git rev-parse --verify --quiet "$TARGET_REF^{commit}" >/dev/null; then
echo "ERROR: target ref '$TARGET_REF' does not exist after fetch" >&2
exit 2
fi
CURRENT_SHA="$(git rev-parse --short HEAD)"
TARGET_SHA="$(git rev-parse --short "$TARGET_REF")"
AHEAD_COUNT="$(git rev-list --count "$TARGET_REF"..HEAD)"
BEHIND_COUNT="$(git rev-list --count HEAD.."$TARGET_REF")"
DIRTY_STATUS="$(git status --porcelain)"
cat <<EOF
WORKTREE RESET PLAN
repo: $REPO_ROOT
current branch: $CURRENT_BRANCH
current HEAD: $CURRENT_SHA
target: $TARGET_REF ($TARGET_SHA)
ahead target: $AHEAD_COUNT commit(s)
behind target: $BEHIND_COUNT commit(s)
dirty: $(if [[ -n "$DIRTY_STATUS" ]]; then echo yes; else echo no; fi)
EOF
if [[ -n "$DIRTY_STATUS" ]]; then
echo "Dirty files:"
git status --short
echo
fi
if [[ "$CONFIRM" -ne 1 ]]; then
cat <<EOF
Dry run only. To execute:
$(realpath "$0") --confirm --remote $REMOTE --branch $BRANCH
If you intentionally want to preserve dirty local changes first:
$(realpath "$0") --confirm --stash --remote $REMOTE --branch $BRANCH
EOF
exit 0
fi
if [[ -n "$DIRTY_STATUS" ]]; then
if [[ "$STASH" -eq 1 ]]; then
STASH_MSG="pre reset-worktree-to-main: $CURRENT_BRANCH $(date -u +%Y-%m-%dT%H:%M:%SZ)"
echo "Stashing dirty worktree: $STASH_MSG"
git stash push -u -m "$STASH_MSG" >/dev/null
else
echo "ERROR: worktree is dirty. Commit, stash, or rerun with --confirm --stash." >&2
exit 2
fi
fi
echo "Resetting $CURRENT_BRANCH to $TARGET_REF ..."
git reset --hard "$TARGET_REF"
cat <<EOF
DONE
branch: $(git branch --show-current)
head: $(git rev-parse --short HEAD) $(git log -1 --pretty=%s)
EOF