Agent skill

smith-git

Git workflow gotchas and non-obvious practices. Use when performing Git commits, merges, branch management, rebasing, or worktree operations. Covers GPG signing, atomic commits, worktree patterns, and safety flags.

Stars 1
Forks 0

Install this agent skill to your Project

npx add-skill https://github.com/tianjianjiang/smith/tree/main/smith-git

SKILL.md

Git Workflow Gotchas

  • Load if: Git commits, merges, branch management
  • Prerequisites: @smith-principles/SKILL.md, @smith-standards/SKILL.md

CRITICAL (Primacy Zone)

  • MUST use git mv for renames (preserves history)
  • MUST GPG sign all commits: git commit -S -m "..."
  • MUST keep branches linear (prefer rebase over merge) - essential for stacked PRs, see @smith-stacks/SKILL.md
  • MUST verify current branch (git branch --show-current) before git commit, git push, or git rebase — confirm it matches the branch you intend to modify
  • NEVER force push to main or shared branches
  • NEVER commit directly to main branch
  • NEVER rebase shared branches (only personal feature branches)
  • NEVER use --no-verify to bypass git hooks
  • NEVER use --no-gpg-sign to skip commit signing

Operation Boundaries

  • NEVER interpret "list", "check", or "show" as permission to create or modify
  • NEVER create branches or tags beyond what was requested
  • Match action to request: list=list, create=create
  • State planned operations before multi-step workflows
  • For scope/approval rules, see @smith-guidance/SKILL.md
  • For PR creation rules, see @smith-gh-pr/SKILL.md

Worktree Safety

  • Before write operations (commits, pushes, dev servers, tests): verify git rev-parse --show-toplevel matches your intended working directory
  • If multiple worktrees exist, use git worktree list to identify the correct one
  • If in wrong worktree: stop, cd to the correct one before proceeding

Worktree Patterns

Git worktree basics:

shell
git worktree add ../feature-branch feat/feature
shell
git worktree list
shell
git worktree remove ../feature-branch

Parallel branch work:

  • Each worktree = independent working directory
  • Share same .git — branches, stash, reflog shared
  • Useful for: hotfix while mid-feature, parallel reviews

Claude Code integration:

  • isolation: "worktree" in Agent tool — auto-creates worktree for subagent, cleaned up when done
  • Manual worktree tools may be available depending on the agent platform (see platform docs for exact tool names)
  • Worktree lifecycle hooks (create/remove) fire on worktree operations for custom automation
  • Agent worktrees auto-cleanup; persistent ones need manual git worktree remove
  • ALWAYS verify worktree path before write operations
  • NEVER leave orphaned worktrees (check git worktree list)
  • Clean up persistent worktrees after branch is merged

Branch Naming

Pattern: type/descriptive_name — type MUST match commit type

Separators (abbreviated quick-ref; see @smith-style/SKILL.md for full rules):

  • Underscore (_): Multi-word single concept → fix/query_processor
  • Hyphen (-): Hierarchy/variant/ticket → feat/auth-login, fix/JIRA-1234-query_processor

Commit Standards

Format: See @smith-style/SKILL.md for conventional commits.

Atomic commits: One logical change per commit, passes tests, reversible.

Non-Obvious Flags

  • -u: Use on first push to set upstream tracking
  • --force-with-lease: Safe force push for personal branches - required for stacked PRs after rebase, see @smith-stacks/SKILL.md
  • --no-ff: Preserve merge commit for feature branches (maintains history)
  • -S: GPG sign commits

Claude Code Plugin Integration

When commit-commands plugin is available:

  • /commit: Auto-generates commit message, stages files, creates commit
  • /clean_gone: Cleans up branches deleted from remote (including worktrees)

Manual commands still needed for:

  • GPG signing (-S flag)
  • Interactive rebase
  • Force push with lease

Ralph Loop Commit Strategy

Atomic commits mark iteration boundaries. Include iteration number; enables git bisect for regressions.

See @smith-ralph/SKILL.md for full commit patterns.

  • @smith-stacks/SKILL.md - Stacked PR workflows (uses linear history, force-with-lease)
  • @smith-gh-pr/SKILL.md - PR creation, review cycles, merge strategies
  • @smith-gh-cli/SKILL.md - GitHub CLI commands
  • @smith-style/SKILL.md - Naming conventions, conventional commits
  • @smith-ctx-claude/SKILL.md - Claude Code agent features and context management

ACTION (Recency Zone)

First push to new branch:

shell
git push -u origin feat/my_feature

Safe force push (personal branches only):

shell
git push --force-with-lease origin feat/my_feature

Feature merge (preserve history):

shell
git merge --no-ff feat/my_feature

Interactive rebase (local commits only):

shell
git rebase -i HEAD~3

Expand your agent's capabilities with these related and highly-rated skills.

tianjianjiang/smith

smith-style

File naming, path standards, and conventional commits. Use when naming files, creating branches, writing commit messages, or setting up new projects. Covers underscore vs hyphen conventions, commit format, and branch naming patterns.

1 0
Explore
tianjianjiang/smith

smith-stacks

Stacked pull request workflows for large features. Use when creating stacked PRs, managing dependent PRs, or rebasing after parent merges. Covers stack creation, merge order, and squash merge handling.

1 0
Explore
tianjianjiang/smith

smith-python

Python development with uv, pytest, ruff, and type hints. Use when writing Python code, running tests, managing Python packages, or working with virtual environments. Covers import organization, type hints, pytest patterns, and environment variables.

1 0
Explore
tianjianjiang/smith

smith-principles

Fundamental coding principles (DRY, KISS, YAGNI, SOLID, HHH). Use when starting any development task, evaluating implementation approaches, or reviewing code quality. Always active as foundation for all development decisions.

1 0
Explore
tianjianjiang/smith

smith-nuxt

Nuxt 3 development patterns including auto-import stubbing for tests, environment variable conventions, and middleware testing. Use when working with Nuxt projects, testing Nuxt components/middleware, or configuring Nuxt environment variables.

1 0
Explore
tianjianjiang/smith

smith-plan

Plan tracking protocol (portable). Progress tracking with checkboxes, iteration workflow, completion/blocker signals. Use when executing multi-step plans, tracking task progress, or working from plan files. IMPORTANT - Always update the plan file after completing tasks.

1 0
Explore

Didn't find tool you were looking for?

Be as detailed as possible for better results