Home
cd ../playbooks
Developer ToolsBeginner

Git Commit & PR Automation

Three streamlined git workflows: commit with an auto-drafted message matching your repo's style, ship a full commit-push-PR in one step, and clean up branches deleted on the remote.

5 minutes
By AnthropicSource
#git#commit#pull-request#github-cli#branch-cleanup#official

You're mid-flow on a feature and git wants your full attention — stage files, write a message, remember the branch naming convention, push, then switch tabs to open a PR with a description nobody will read anyway. Every context switch costs you the thread you were pulling on.

Who it's for: developers who want cleaner git history, teams establishing commit conventions, engineers who create PRs frequently, anyone whose local branch list is cluttered with merged branches

Example

"Ship this as a PR" → New branch created if you're on main, a commit written to match your repo's existing message style, pushed to origin, and a PR opened with a summary and test-plan checklist covering the whole branch history — not just the last commit

CLAUDE.md Template

New here? 3-minute setup guide → | Already set up? Copy the template below.

# Git Commit & PR Automation

## Your Role

You handle my git mechanics so I don't context-switch out of the work. Three workflows: commit, ship a PR, and clean up stale branches.

---

## Workflow 1: Commit

When I ask you to commit:

### Gather context

Run these and read the output before doing anything:

```bash
git status
git diff HEAD          # staged and unstaged changes
git branch --show-current
git log --oneline -10  # learn the repo's message style
```

### Then

1. Analyze what actually changed
2. Study the recent commits — match the repo's existing message style, don't impose your own
3. Draft an appropriate commit message
4. Stage the relevant files
5. Create the commit

**Do all of this in a single message with parallel tool calls.** Don't narrate. Don't send extra text. Just the tool calls.

### Never commit

- `.env`, `.env.local`, or any environment file
- `credentials.json`, `secrets.yaml`, keystore files, `.pem` files
- Anything with a hardcoded API key, token, or password
- Build output or `node_modules` unless the repo deliberately tracks them

If staged changes contain a secret, stop and tell me instead of committing.

---

## Workflow 2: Commit, Push, and Open a PR

When I ask you to ship a PR:

### Gather context

```bash
git status
git diff HEAD
git branch --show-current
```

### Then, in a single message

1. **Create a new branch if I'm on main.** Never commit directly to the default branch.
2. Create a single commit with an appropriate message
3. Push the branch to `origin`
4. Create the pull request with `gh pr create`
5. Give me the PR URL

### PR description format

Analyze **all commits in the branch**, not just the latest one. The PR description should cover the whole branch:

```markdown
## Summary
- 1–3 bullets describing what changed and why

## Test plan
- [ ] Specific, checkable verification steps
- [ ] How a reviewer confirms this works
```

### Requirements

- GitHub CLI (`gh`) installed and authenticated (`gh auth login`)
- A remote named `origin`

---

## Workflow 3: Clean Up Gone Branches

When I ask you to clean up stale branches — branches deleted on the remote that still exist locally:

### Step 1: List branches and find `[gone]` status

```bash
git branch -v
```

Branches with a `+` prefix have associated worktrees. Their worktrees must be removed before the branch can be deleted.

### Step 2: List worktrees

```bash
git worktree list
```

### Step 3: Remove worktrees and delete gone branches

```bash
git branch -v | grep '\[gone\]' | sed 's/^[+* ]//' | awk '{print $1}' | while read branch; do
  echo "Processing branch: $branch"
  worktree=$(git worktree list | grep "\[$branch\]" | awk '{print $1}')
  if [ ! -z "$worktree" ] && [ "$worktree" != "$(git rev-parse --show-toplevel)" ]; then
    echo "  Removing worktree: $worktree"
    git worktree remove --force "$worktree"
  fi
  echo "  Deleting branch: $branch"
  git branch -D "$branch"
done
```

Report which worktrees and branches were removed. If nothing was marked `[gone]`, say no cleanup was needed.

**If no branches show `[gone]`**: run `git fetch --prune` first to refresh remote tracking. A branch only shows as gone once it's actually deleted on the remote.

---

## Suggested Rhythm

**During development**
```
write code → commit → keep going → commit
```

**Ready to ship**
```
commit-push-pr
```

**After a few PRs merge**
```
clean up gone branches
```

Run the cleanup weekly to keep the local branch list readable.

---

## Rules

- Match the repo's commit message conventions — read `git log` first, every time
- Never commit secrets or environment files
- Never commit directly to the default branch; branch first
- Analyze the full branch history for PR descriptions, not just HEAD
- Show me the commit message before pushing if the change is large or ambiguous
- Cleanup only removes branches already deleted on the remote — it's safe, but report what it did

Get new playbooks like this one

One email a week with new Claude Code workflows. Free, like everything here.

No spam. Unsubscribe anytime.

README.md

What This Does

Three focused git workflows in one CLAUDE.md: /commit for a single well-formed commit, /commit-push-pr for the full ship sequence, and a [gone]-branch cleanup routine. Each reads actual repo context — git status, git diff, recent commit style — before acting, rather than guessing at conventions.


Quick Start

Step 1: Navigate to Your Repository

cd ~/your-project

Step 2: Download the Template

Click Download above, then:

mv ~/Downloads/CLAUDE.md ./

Step 3: Use It

claude

Then say: "Commit these changes", "Ship this as a PR", or "Clean up my stale branches".


The Three Workflows

Commit

Reads git status, git diff HEAD, current branch, and the last 10 commits to learn your message style — then stages relevant files and commits, matching your repo's conventions rather than imposing generic ones.

Commit, Push, and Open a PR

Creates a new branch if you're on main (never commits directly to the default branch), commits, pushes to origin, and opens a PR with gh pr create. The PR description covers the entire branch history, not just the latest commit — summary bullets plus a checkable test plan.

Clean Up Gone Branches

Finds local branches whose remote counterpart was deleted (git branch -v shows [gone]), removes any associated worktrees first, then deletes the branches. Safe to run repeatedly — it only ever touches branches already gone from the remote.


Tips & Best Practices

  • Never commits secrets.env, credentials.json, and anything with a hardcoded key gets excluded automatically
  • Requires gh CLI, authenticated, for the push-PR workflow (gh auth login)
  • Run git fetch --prune first if the cleanup workflow reports nothing to clean — branches only show as [gone] after the remote tracking refreshes
  • Combine them: /commit during development, /commit-push-pr when ready to ship, /clean_gone weekly for maintenance

Troubleshooting

Commit comes back empty — verify you actually have staged or unstaged changes with git status.

PR creation fails — confirm gh is installed and authenticated, and that the repo has an origin remote pointing to GitHub.

Cleanup finds no [gone] branches — run git fetch --prune to refresh remote-tracking branches first.

$Related Playbooks

Developer Tools

AI Crawler Access Audit: Who Can Actually Read Your Site

Maps 14 AI crawlers against your robots.txt, meta tags, and HTTP headers, then returns an access score and the exact rules to change

10 minutes
Intermediate
Developer Tools

llms.txt Generator & Auditor

Generate and validate llms.txt, the root-level Markdown file that tells AI systems what your site is and which pages to cite

10 minutes
Intermediate
Developer Tools

GEO Schema: Structured Data for AI Citation

Audit and generate schema.org JSON-LD built for AI comprehension, with a sameAs entity graph, knowsAbout topics, and a 0-100 scoring rubric

10 minutes
Intermediate
Developer Tools

GEO Technical SEO Audit: 8 Categories, 100 Points

A scored technical audit covering crawlability, indexability, security, Core Web Vitals, and the server-side rendering check that decides whether AI crawlers see your content at all

15 minutes
Advanced
Developer Tools

GEO Toolkit Updater

Pull the latest geo-seo-claude skills, agents, scripts, and schema templates from upstream, with a diff summary before anything is overwritten

5 minutes
Beginner
Developer Tools

Full-Output Enforcement: No Placeholders, No Stubs

A short rule set that bans TODO comments, skeleton code, and 'rest follows the same pattern' shortcuts so Claude always delivers complete, runnable output

2 minutes
Beginner
Developer Tools

GPT Taste Skill: Strict Anti-Slop UI Rules

A stricter, more deterministic anti-slop frontend ruleset with GSAP motion patterns, despite the GPT-oriented name it works as a standard CLAUDE.md in Claude Code

5 minutes
Intermediate
Developer Tools

GitHub Contributor

A phase-based playbook for shipping pull requests maintainers actually merge — discovery, CONTRIBUTING compliance, PR-size checks, minimal diffs, and post-submission interaction.

20 minutes
Intermediate
Developer Tools

GitHub Operations

Comprehensive GitHub operations using the gh CLI and REST/GraphQL APIs — PRs, issues, repositories, workflows, and bulk operations across public and Enterprise GitHub.

10 minutes
Intermediate
Developer Tools

Frontend Enhancer

Enhance Next.js applications with modern visual design, production-ready components, color palettes, animations, and responsive layout templates.

10 minutes
Intermediate
Developer Tools

Idea-to-Design Brainstorming Gate

A hard approval gate before any implementation — classify every request as a Spike, Bounded change, or Architectural project, then design collaboratively and never write code until the design is explicitly approved.

5 minutes
Intermediate
Developer Tools

Hookify Guardrails

Create custom Claude Code guardrails with lightweight markdown rule files instead of hand-editing hooks.json — pattern matching, no restart required, rules live-load on the next tool call.

5 minutes
Beginner

Browse all Developer Tools playbooks →