DEV Community

brian austin
brian austin

Posted on

Claude Code git workflow: commit, branch, and review with AI in your terminal

Claude Code git workflow: commit, branch, and review with AI in your terminal

If you use Claude Code and git together, you're probably doing it manually — staging files, writing commit messages, switching branches by hand.

Here's how to let Claude Code handle the git workflow so you can focus on the actual code.

The basic pattern

Claude Code can run shell commands, which means it can run git commands. The key is knowing when to ask it to.

# Instead of:
git add -A && git commit -m "fix: update user auth flow"

# Ask Claude:
"Commit the auth changes with a descriptive message"
Enter fullscreen mode Exit fullscreen mode

Claude will:

  1. Check git status to see what changed
  2. Stage the relevant files (not everything blindly)
  3. Write a commit message that actually describes the change
  4. Run the commit

Branch management

# Ask Claude to:
"Create a feature branch for the payment refactor and switch to it"

# It runs:
git checkout -b feature/payment-refactor
Enter fullscreen mode Exit fullscreen mode

More usefully, when you're working on multiple tasks in parallel:

# Describe the work, let Claude pick the branch name:
"Start a new branch for fixing the rate limiter, name it something sensible"
Enter fullscreen mode Exit fullscreen mode

Writing better commit messages

Conventional commits format works well with Claude:

feat: add retry logic to API client
fix: handle null user in session middleware  
refactor: extract auth helpers to separate module
docs: update CLAUDE.md with new payment flow
Enter fullscreen mode Exit fullscreen mode

Tell Claude in your CLAUDE.md to use conventional commits:

## Git conventions
- Use conventional commits: feat/fix/refactor/docs/test/chore
- Keep subject line under 72 chars
- Reference issue numbers when relevant: "fix: handle null session (#142)"
Enter fullscreen mode Exit fullscreen mode

Now every commit Claude makes follows your project standard.

Code review before commit

Before committing, you can ask Claude to review its own changes:

"Show me a diff of what you're about to commit and flag anything risky"
Enter fullscreen mode Exit fullscreen mode

Claude runs git diff --staged, reads the output, and tells you:

  • What changed and why
  • Any potential issues (hardcoded values, missing error handling, etc.)
  • Whether the commit message matches the actual change

This catches mistakes before they hit your history.

The parallel agent git pattern

When running multiple Claude agents on separate tasks, branches prevent merge conflicts:

Agent 1: feature/auth-refactor
Agent 2: feature/payment-flow  
Agent 3: fix/rate-limiter
Main:     develop
Enter fullscreen mode Exit fullscreen mode

Each agent commits to its branch. You merge when done.

# Agent 1 finishes:
git checkout develop
git merge feature/auth-refactor --no-ff -m "merge: auth refactor complete"

# Agent 2 finishes:
git merge feature/payment-flow --no-ff -m "merge: payment flow complete"
Enter fullscreen mode Exit fullscreen mode

No conflicts. Clean history. Each agent's work is isolated.

Stashing mid-session

When you need Claude to switch context mid-task:

"Stash what you're working on and help me debug this production issue"
Enter fullscreen mode Exit fullscreen mode

Claude runs git stash, helps with the urgent issue, then git stash pop to resume.

Interactive rebase (carefully)

For cleaning up messy commit history before a PR:

"Squash the last 4 commits into one clean commit describing the feature"
Enter fullscreen mode Exit fullscreen mode

Claude handles the interactive rebase, combining the commits with a sensible message.

⚠️ Don't do this on shared branches. Only on your local feature branch before merging.

PR descriptions

When you're ready to push:

"Generate a PR description for this branch against develop"
Enter fullscreen mode Exit fullscreen mode

Claude reads the commit history, diffs, and any related files, then writes:

  • What changed and why
  • How to test it
  • Any breaking changes or migration steps

Copy-paste into GitHub. Done.

Rate limits during long git operations

If you're doing a big refactor across many files — auth system rewrite, database migration, API redesign — Claude Code will hit rate limits mid-session.

You'll be in the middle of a complex branch rebase and suddenly:

Rate limit reached. Please wait before continuing.
Enter fullscreen mode Exit fullscreen mode

The fix is setting ANTHROPIC_BASE_URL to route through a proxy with higher limits:

export ANTHROPIC_BASE_URL=https://simplylouie.com/api/proxy
Enter fullscreen mode Exit fullscreen mode

SimplyLouie is ✌️2/month with no rate limits — less than a coffee. Useful when you're mid-rebase and can't stop.

The complete CLAUDE.md git section

## Git workflow

### Branches
- main: production only, never commit directly
- develop: integration branch  
- feature/*: new features
- fix/*: bug fixes
- Always branch from develop, merge back to develop

### Commits
- Conventional commits: feat/fix/refactor/docs/test/chore
- Subject line: max 72 chars, imperative mood
- Reference issues: "fix: handle null session (#142)"

### Before committing
1. Run tests (npm test)
2. Check diff with git diff --staged
3. Verify commit message matches actual change

### PRs
- Always against develop (not main)
- Include: what, why, how to test, breaking changes
Enter fullscreen mode Exit fullscreen mode

With this in CLAUDE.md, Claude handles git the same way every session without reminders.

Summary

  • Claude Code can handle your entire git workflow via shell commands
  • CLAUDE.md is where you encode your git conventions
  • Branch-per-agent prevents conflicts in parallel sessions
  • Set ANTHROPIC_BASE_URL to avoid rate limit interruptions on long operations
  • Ask Claude to review diffs before committing — it catches its own mistakes

Git is just another shell tool. Claude can use it.

Top comments (0)