G

Git Workflow Pro

All-in-one agent covering agent, need, design, establish. Includes structured workflows, validation checks, and reusable patterns for git.

AgentClipticsgitv1.0.0MIT
0 views0 copies

Git Workflow Pro

Your agent for advanced git operations — covering rebasing, cherry-picking, bisecting, stashing, worktrees, and resolving complex git scenarios.

When to Use This Agent

Choose Git Workflow Pro when:

  • Performing complex git operations (interactive rebase, cherry-pick, bisect)
  • Resolving merge conflicts, detached HEAD, or corrupted history
  • Using advanced git features (worktrees, submodules, subtrees, hooks)
  • Recovering from git mistakes (force push, lost commits, broken rebase)
  • Optimizing git workflows for large repositories

Consider alternatives when:

  • You need branching strategy decisions — use a Git Flow Manager agent
  • You need commit message conventions — use a Commit Navigator agent
  • You need CI/CD integration — use a DevOps agent

Quick Start

# .claude/agents/git-workflow.yml name: Git Workflow Pro model: claude-sonnet tools: - Read - Write - Edit - Bash - Glob - Grep description: Advanced git operations agent for rebasing, cherry-picking, bisecting, and resolving complex git scenarios

Example invocation:

claude "I accidentally force-pushed over my colleague's commits on the develop branch. Help me recover their commits and restore the branch to include both our changes"

Core Concepts

Advanced Git Operations

OperationCommandUse Case
Interactive Rebasegit rebase -i HEAD~5Clean up commit history
Cherry-Pickgit cherry-pick abc123Apply specific commits to another branch
Bisectgit bisect start/good/badFind the commit that introduced a bug
Stashgit stash push -m "message"Temporarily save uncommitted changes
Worktreegit worktree add ../feature branchWork on multiple branches simultaneously
Refloggit reflogRecover lost commits and branches

Git Recovery Techniques

# Recover after bad force push git reflog # Find the commit before force push git reset --hard HEAD@{n} # Reset to that point git push --force-with-lease # Push safely # Recover deleted branch git reflog --all | grep "branch-name" # Find last commit on deleted branch git checkout -b branch-name abc123 # Recreate from that commit # Undo a rebase git reflog # Find pre-rebase HEAD git reset --hard HEAD@{n} # Reset to pre-rebase state # Find bug-introducing commit git bisect start git bisect bad # Current commit has the bug git bisect good v1.0 # v1.0 was working # Git checks out midpoint, test, mark good/bad, repeat

Configuration

ParameterDescriptionDefault
safety_levelGuard against destructive ops (safe, normal, expert)safe
merge_strategyDefault merge approach (merge, rebase, squash)rebase
auto_stashAuto-stash before operationstrue
force_push_policyForce push behavior (never, lease-only, allowed)lease-only
large_repo_modeOptimizations for large repos (shallow, sparse, partial)off

Best Practices

  1. Use --force-with-lease instead of --force for push. Force-with-lease checks that the remote branch hasn't changed since your last fetch, preventing accidental overwrites of others' work. Regular --force blindly overwrites everything.

  2. Rebase interactively before merging feature branches. Use git rebase -i to squash fixup commits, reword vague messages, and reorder commits logically. Clean history makes code review easier and git bisect more effective.

  3. Use git bisect for regression hunting. When you know a feature worked in version X but is broken in version Y, bisect automatically binary-searches through commits to find the exact commit that introduced the bug.

  4. Stash with descriptive messages. git stash push -m "WIP: auth refactor, needs token validation" is infinitely more useful than git stash when you return to it a week later. List stashes with git stash list and apply by index or message.

  5. Use worktrees for working on multiple branches simultaneously. Instead of stashing and switching branches, create a worktree: git worktree add ../hotfix hotfix-branch. This lets you work on the hotfix without disrupting your feature branch checkout.

Common Issues

Interactive rebase causes merge conflicts on every commit. This happens when rebasing many commits over a diverged base. Consider rebasing in smaller chunks, using git rerere to remember conflict resolutions, or squashing commits before rebasing.

Cherry-pick creates duplicate commits when branches later merge. Git doesn't know that a cherry-picked commit is the "same" as the original. When both branches merge, you get duplicate changes. Use git rebase --onto instead of cherry-pick when possible, or accept the duplication as a minor inconvenience.

Reflog entries expire and lost commits become unrecoverable. Git prunes unreferenced objects after 90 days by default. If you need to recover old commits, check the reflog promptly. For important branches, create backup tags: git tag backup/feature-v1 feature-branch.

Community

Reviews

Write a review

No reviews yet. Be the first to review this template!

Similar Templates