/project-toolkit:git-advanced-workflowsfrom project-toolkit
Advanced Git workflows for rebasing, cherry-picking, bisect, worktrees, and reflog. Helps manage complex histories, collaborate on feature branches, and recover from repo issues.
Ships in project-toolkit. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
Advanced Git techniques for clean history, effective collaboration, and confident recovery.
| Trigger Phrase | Operation |
|---|---|
rebase my branch | Interactive or standard rebase guidance |
cherry-pick a commit | Cherry-pick with conflict resolution |
find the breaking commit | Git bisect workflow |
recover lost commits | Reflog exploration and recovery |
sync or publish a dirty checkout | Commit local work and bring the branch up to date, or move only requested files to a clean topic branch |
git status, git log --oneline -10git branch backup-<timestamp>
git branch backup-$(date +%s)git branch backup-$(Get-Date -UFormat %s)git checkout feature/user-auth
# Record the remote tip BEFORE rewriting. A later fetch moves the tracking
# ref, so reading it at push time would let the lease overwrite new commits.
git fetch origin
EXPECTED_REMOTE_SHA=$(git rev-parse origin/feature/user-auth)
git rebase -i main
# Squash "fix typo" commits, reword messages, reorder logically
git push --force-with-lease="refs/heads/feature/user-auth:$EXPECTED_REMOTE_SHA" \
origin HEAD:refs/heads/feature/user-auth
Rebase operations: pick (keep), reword (change message), edit (amend content), squash (combine keeping message), fixup (combine discarding message), drop (remove).
Autosquash pattern:
git commit --fixup HEAD # Mark as fixup for previous commit
git rebase -i --autosquash main # Auto-marks fixup commits
Split a commit:
git rebase -i HEAD~3 # Mark commit with 'edit'
git reset HEAD^ # Reset commit, keep changes in working tree (unstaged)
git add file1.py && git commit -m "feat: add validation"
git add file2.py && git commit -m "feat: add error handling"
git rebase --continue
git checkout main
git commit -m "fix: critical security patch"
git checkout release/2.0
git cherry-pick abc123
git checkout release/1.9
git cherry-pick abc123
# On conflict: fix files, git add, git cherry-pick --continue
Partial cherry-pick (specific files only):
git show --name-only abc123
git restore --staged --worktree --source=abc123 -- path/to/file1.py path/to/file2.py # --staged stages the changes so the following commit captures them
git commit -m "cherry-pick: apply specific changes from abc123"
git bisect start
git bisect bad HEAD
git bisect good v2.1.0
# Git checks out middle commit. Run tests, mark good/bad, repeat.
git bisect reset # When done
Automated bisect:
git bisect start HEAD v2.1.0
git bisect run ./test.sh
# test.sh: exit 0 = good, 125 = skip, any other non-zero = bad
git worktree add ~/worktrees/myapp-hotfix hotfix/critical-bug
# Work in the new worktree using the -C flag to avoid changing the current directory.
# e.g., git -C ~/worktrees/myapp-hotfix commit -a -m "fix: critical bug"
git worktree remove ~/worktrees/myapp-hotfix # Clean up when done
git worktree prune # Remove stale entries
Publish requested files from a stale or dirty checkout. Leave the source checkout untouched, and move only the requested paths to a clean topic branch:
--binary lets binary files apply. Copy requested untracked files directly.user.name and user.email. Add a
DCO sign-off (-s) when the repository requires one.HEAD.git fetch origin
git -C <source> status --short --branch
git worktree add -b <feature> <worktree> origin/<base>
base=$(git -C <source> merge-base HEAD origin/<base>)
# Exit 0 means upstream never touched the path since the merge base
git -C <source> diff --quiet HEAD...origin/<base> -- <path>
git -C <source> diff --binary "$base" -- <path> | git -C <worktree> apply --index
cmp <source>/<path> <worktree>/<path>
git -C <worktree> diff --cached --name-only
git -C <worktree> commit -m "<type>(<scope>): <desc>"
git -C <worktree> fetch origin && git -C <worktree> rebase origin/<base>
git -C <worktree> push origin HEAD:refs/heads/<feature>
git -C <worktree> fetch origin
test "$(git -C <worktree> rev-parse HEAD)" = "$(git -C <worktree> rev-parse origin/<feature>)"
Move-safe caveat: moving a worktree after uv created .venv leaves the
absolute-path shebangs in .venv/bin/* (POSIX) or .venv/Scripts/* (Windows)
stale, so direct .venv/bin/pytest calls fail with "bad interpreter". Run
scripts/maintenance/repair_worktree_venv.py with uv run python (or run
uv sync --frozen --extra dev --reinstall) to rewrite them, and prefer
uv run python -m pytest for move-safe validation. Each flag earns its place:
--reinstall recreates the launchers (a plain --frozen sync no-ops when the
packages already appear installed and leaves the stale shebangs unrewritten),
--extra dev keeps pytest/ruff/mypy in the repaired venv, and --frozen
reproduces uv.lock without re-resolving so the result matches CI.
Shared-state caveat: every worktree shares one .git. Only HEAD and the
other pseudorefs, the index, the working tree, refs/bisect/*,
refs/worktree/*, and refs/rewritten/* belong to one worktree. Every branch,
every tag, refs/remotes/*, and refs/stash are shared. Three traps follow
when several sessions work one clone at once:
| Hazard | Symptom | First command | Fix |
|---|---|---|---|
| Stash is repo-wide | git stash list shows an entry you never made, or git stash pop conflicts on a file you never touched | git stash list --format='%gd %gs' and read the WIP on <branch> subject | Pop only an entry that names your branch, by index, onto a clean tree. Undo a foreign pop with the steps below. Save your own work as a WIP commit on your branch instead of stashing |
| Base goes stale in long runs | Gates or conflicts appear on files you never touched, after a local run was green | git fetch origin main && git rev-list --left-right --count origin/main...HEAD | A non-zero left count means your branch lacks commits on main. git merge origin/main, regenerate, and re-run the failing gate. A fetch in any worktree moves origin/main for all of them but never moves your branch |
| "Next free number" races | Two branches add the same sequential id (spec, ADR, record) and each passes alone | After git merge origin/main, re-run the id-uniqueness check | Renumber the unmerged side. Allocate the id after a fresh fetch, as late as possible before commit |
Undo a foreign pop. Git refuses a pop over unstaged edits to the same
path, but merges it into staged edits. Do not reset to HEAD; that discards
your staged work. Record the entry first: sha=$(git rev-parse 'stash@{N}').
UU path, run
git checkout --ours -- <path> && git add -- <path>. Stage 2 holds your
pre-pop version, staged edits included. Then reverse the paths it applied
cleanly: git diff "$sha^1" "$sha" -- <paths> | git apply -R --index.git stash store -m restored <sha>, taking <sha> from the
Dropped refs/stash@{0} (<sha>) line. Reverse it the same way; for a path
you had staged, drop --index.When asked to commit local changes and bring the checkout up to date, inspect
git status --short --branch, the current branch, remotes, and
git log -1 --oneline. Fetch the intended remote and measure divergence with
git rev-list --left-right --count <remote>/<branch>...HEAD. The left count is
remote-ahead and the right count is local-ahead, the same orientation as the
Shared-state table above.
Review the complete working-tree diff, including untracked files, before
staging. Stage only intended paths, inspect the staged names and diff, run
git diff --cached --check, and commit. git rebase refuses to start while
unstaged edits remain, so deal with the leftovers first. If any leftover is
unrelated to the request, use the Publish procedure above instead, so it never
reaches the remote. If the leftovers are your own unfinished work on this
branch, commit them as a separate WIP commit on top, and unwind it before any
push (see below). Do not use --autostash: the stash is repo-wide (see the
Shared-state caveat).
If the branch is behind and private, create a safety branch (Phase 1 step 3), then rebase local commits onto the fetched remote head. Use a merge for a shared branch. Do not reset away local commits or discard working-tree changes to make the graph look current.
If the rebase conflicts, inspect the base, the local commit, and the conflict
hunks before resolving each file. During a rebase, --ours is the branch being
rebased onto (upstream) and --theirs is your local commit, the reverse of a
merge. That swap is the usual reason a mechanical pick discards the wrong side.
Never choose either side mechanically: one commit can hold valuable changes on
both sides.
After integration, confirm every intended path is committed and the left
(remote-ahead) count is 0. A non-zero right count is committed work not yet
published. If the user asked for the remote to hold the work too, first
unwind any WIP commit with git reset HEAD^, which returns its edits to the
working tree and keeps them out of the push. Then push the branch, fetch
again, and confirm the count is 0 0 and the remote ref equals HEAD.
git reflog # Find lost commit hash
git reset --hard def456 # Restore to that state
# Or create branch: git branch recovery def456
Abort operations in progress:
git rebase --abort
git merge --abort
git cherry-pick --abort
git bisect reset
Other recovery commands:
git restore --source=abc123 path/to/file # Restore file from commit
git reset --soft HEAD^ # Undo commit, keep changes staged
git reflog # 1. Find the hash of the desired commit
git branch recovered abc123 # 2. Create a branch from that hash (within reflog retention; ~90 days by default, configurable)
A dirty worktree proves someone once started, not that anyone is working now.
Before standing down on an issue because a worktree looks owned, or before
removing a worktree whose tip may be unreachable, follow
references/worktree-triage.md: measure the newest file age (live means under
about 60 minutes), confirm with git -C "$p" status --porcelain, join the
fleet against gh pr list --state all --json number,state,headRefName,headRefOid,
and anchor every unreachable tip with git update-ref refs/salvage/... plus a
verified bundle before git worktree remove.
git statusgit log --oneline matches expectationsgit worktree list| Use Rebase | Use Merge |
|---|---|
| Cleaning local commits before push | Integrating completed features into main |
| Keeping feature branch current with main | Preserving exact collaboration history |
| Creating linear history for review | Public branches used by others |
| Avoid | Why | Instead |
|---|---|---|
| Rebasing shared branches | Rewrites history for all collaborators | Merge for shared branches |
--force, or a bare --force-with-lease | Overwrites teammates' work; a fetch can advance the lease's expected value | Pin the lease to an observed SHA: --force-with-lease=<ref>:<sha> |
| Bisecting on dirty working tree | Checkout fails with uncommitted changes | Commit or stash first |
| Orphaned worktrees | Consume disk space silently | Remove after use |
git stash with several live worktrees | One stash stack serves every worktree; pop takes the newest entry, whoever made it | WIP commit on your own branch |
| Treating a dirty worktree as owned | Freezes issues whose worktree a fleet wipe orphaned | Measure file age and list files (references/worktree-triage.md) |
| Removing a worktree before anchoring its tip | Drops commits nothing else references | git update-ref refs/salvage/<slug> <sha> and bundle first |
| No backup before complex rebase | No recovery path if rebase fails | Create safety branch first |
git status)git log --oneline)--force-with-lease=<ref>:<sha> to an observed SHAgit worktree list)What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
npx claudepluginhub rjmurillo/ai-agents --plugin project-toolkit105 skills in this plugin
/adr-generatorCreate comprehensive Architectural Decision Records (ADRs). Researches the destination directory to detect existing template conventions, gathers context, determines next ADR number, generates the ADR, validates completeness, and saves. Supports multiple ADR formats (MADR, Nygard, Alexandrian, project canonical). Use when documenting technical decisions, creating new ADR files, or capturing rationale so future readers can revisit a choice. Use when you say "write an ADR", "document this decision", "document these design choices", "record why we chose this", "capture the rationale", or "for future maintainers", or when creating an ADR-like markdown file under docs/decisions/, docs/adr/, docs/architecture/, architecture/decisions/, or .project-toolkit/architecture/. Do NOT use to debate or review an existing ADR (use adr-review)./adr-reviewMulti-agent debate orchestration for Architecture Decision Records. Automatically triggers on ADR create/edit/delete. Coordinates architect, critic, independent-thinker, security, analyst, and high-level-advisor agents in structured debate rounds until consensus. Use when you say "review this ADR", when an ADR is created/edited/deleted, or when reviewing, accepting, or updating a decision file under .project-toolkit/architecture/, docs/architecture/, docs/decisions/, docs/adr/, or architecture/decisions/, including intent like "review this decision record" or "check this rationale for future maintainers". Do NOT use to author a new ADR (use adr-generator)./agent-harness-referenceField reference for Claude Code and GitHub Copilot CLI hook contracts. Covers hook locations, events, matchers, payloads, decisions, exit codes, timeouts, plugin roots, and cloud limits with official URLs and versioned probes. Use for `harness contract`, `copilot cli hook behavior`, `hook payload format`, `stale plugin root`, `Errno 2 _dispatch.py`, or before changing cross-harness hooks. Do NOT use to run the porting campaign (in the ai-agents repository, use `ai-agents-portability-campaign`)./ai-agents-external-claimsVerify external, vendor, and third-party claims (numbers, attributions, structure) against authoritative primary sources before they land in a repo artifact or external deliverable. Covers stake-holding sources, round-number tells, citation-chain drift, and the walk-the-gate-or-file-conservative discipline. Use when you say `verify an external claim`, `check a vendor number`, `is this stat real`, `validate a third-party citation`. Do NOT use for running an experiment (use `ai-agents-research-methodology` in the ai-agents repository) or command-injection scanning (use `security-scan`)./analysis-provenanceIdentify code ownership before modifying validators or linters. Checks file headers for provenance indicators, reviews documentation, and determines provenance as UPSTREAM, LOCAL, VENDOR, or UNKNOWN. Prevents accidental modification of upstream tools./analyzeSystematic multi-step codebase analysis producing prioritized findings with file-line evidence. Covers architecture reviews, security assessments, and code quality evaluations through guided exploration, investigation planning, and synthesis. Use when you say "analyze this codebase", "run security assessment", "architecture review of this system", "find code smells", or "review code quality" across multiple files. Do NOT use for single-file maintainability scoring (use code-qualities-assessment) or CWE-78 injection pattern scanning (use security-scan).2 plugins in one repository ship this exact skill · first indexed Nov 13, 2026
Other plugins' skills for the same job