# git-workflow-master

> A Claude Code agent persona that enforces atomic commits, conventional commit messages, and safe rebase/force-push discipline — picking trunk-based or Git Flow per team and routing every dangerous command through `--force-with-lease`.

**Use case**: Keep a clean, navigable git history without bikeshedding every PR

**Canonical URL**: https://agentcookbooks.com/skills/git-workflow-master/

**Topics**: claude-code, skills, git, code-quality

**Trigger phrases**: "clean up this branch", "rebase before merge", "set up a git workflow"

**Source**: [Michael Sitarzewski](https://github.com/msitarzewski/agency-agents/blob/main/engineering/engineering-git-workflow-master.md)

**License**: MIT

---

## What it does

`git-workflow-master` is the version-control persona in the agency-agents collection. It picks the right branching strategy for the team (trunk-based by default; Git Flow only when versioned releases require it), enforces atomic conventional-commit history (`feat:`, `fix:`, `chore:`, `docs:`, `refactor:`, `test:`), and routes every potentially destructive operation through its safe variant — `--force-with-lease` instead of `--force`, interactive rebase before merge, and meaningful branch names like `feat/user-auth` rather than `mybranch2`.

Five rules govern the persona's output: atomic commits that revert independently, conventional format, never force-push shared branches, always rebase on the target before merging, and meaningful branch names. Recovery steps ship alongside risky operations — the persona explains the reflog before suggesting anything that touches it.

## When to use it

- Cleaning up a branch with WIP commits before opening a PR (squash, reword, drop)
- Resolving a merge conflict where you want the rebase-vs-merge tradeoff explained
- Standing up a branching strategy for a new repo or new team
- Recovering a "lost" commit (detached HEAD, force-pushed branch) where reflog or `git fsck` is the answer
- Pairing with `using-git-worktrees` from obra/superpowers — the worktree skill creates isolation, this one keeps the history clean inside it

When *not* to reach for it:

- One-line fixes on `main` where an atomic commit is already what you'd write
- Repos where the team has explicitly chosen non-conventional commit messages (don't fight house style)
- Projects using Gerrit, Jujutsu, or other non-Git VCS — the persona's mental model assumes Git primitives

## Install

From [msitarzewski/agency-agents](https://github.com/msitarzewski/agency-agents) at `engineering/engineering-git-workflow-master.md`. Copy to `~/.claude/agents/` or use the repo's installer. Standalone — pairs naturally with worktree and code-review personas but doesn't require them.

## What a session looks like

1. **Diagnose the state.** `git status`, `git log --oneline origin/main..HEAD`, `git diff origin/main` — what's the actual delta, what does the history look like, is the branch ahead of `origin/main` cleanly or behind.
2. **Pick the operation.** Cleanup before PR? Interactive rebase. Resolve conflict? Rebase or merge depending on whether the branch is shared. Recover work? Reflog. The persona names the operation before running it.
3. **Show the safe form.** `git push --force-with-lease` instead of `git push --force`. `git rebase -i origin/main` instead of `git rebase main` from a stale base. `git branch -d` instead of `git branch -D`.
4. **Run it, narrate the diff.** Each commit gets a one-line summary; conflict resolution gets file-by-file reasoning rather than blanket "accept theirs".
5. **Recovery on standby.** Before any rewrite, the persona prints the pre-rewrite `HEAD` SHA so reflog recovery is one command away.

The discipline that makes it work: rule 3, "never force-push shared branches." The persona will refuse a plain `--force` against an upstream branch and substitute `--force-with-lease` automatically — the difference between "I overwrote my own work" and "I overwrote someone else's work."

## Receipts

### 2026-05-05 — Read-only assessment of the current branch state

Pointed the persona at this repo with two modified files in the working tree (`src/layouts/Base.astro`, `src/content/blog/skill-security-auditor-not-a-website-tool.md`) and an explicit "don't run any destructive operation, just recommend." Persona ran 5 read-only commands (`git status`, `git diff --stat`, `git log -10 --oneline`, `git branch --show-current`, `git remote -v`) and produced a structured assessment.

The receipt-worthy finding was the coherence call: those 2 files are **one logical commit, not two**. Both come from the same May 4–5 metaDesc smart-truncate session described in `session.md` (the helper in `Base.astro` caps SERP descriptions at 160 chars; the blog post lede was padded 72→133 words in the same pass for the AI-citation band). Suggested message: `Cap meta descriptions at 160 chars + pad skill-security-auditor lede`. Persona then proactively applied the project's "ask before src/ edits" policy — recommended *Hold* pending operator go-ahead rather than committing on its own — without being given the policy file by name, just the repo's existence.

Honest scope: persona was emulated (general-purpose agent + persona's described framing). The `--force-with-lease` substitution rule didn't apply (no force-push needed); the conventional-commit rule and atomic-commit rule both did, and the "name the operation before running it" discipline produced the cleaner-than-default output.

## Source and attribution

From [Michael Sitarzewski's agency-agents repository](https://github.com/msitarzewski/agency-agents/blob/main/engineering/engineering-git-workflow-master.md), an MIT-licensed collection of 144+ AI agent personas across engineering, marketing, design, testing, and specialized roles.

License: MIT.

Quote from the persona body, verbatim: *"Clean history, atomic commits, and branches that tell a story."* The five rules and the `--force-with-lease` substitution are how the persona makes that stance operational instead of aspirational.