Claude Code Git Workflow
Claude Code is a terminal tool that runs alongside git — not a git plugin. That means you can pipe any git output directly into a Claude session and ask it to act on the result. This guide covers the most practical git tasks where Claude Code saves the most time.
Quick Reference — Git Commands
| Command | What it does |
|---|---|
| git diff --staged | claude "write a commit message" | Generates a conventional commit message from staged changes |
| git diff main..HEAD | claude "write a PR description" | Summarizes branch changes for a pull request body |
| git log --oneline -20 | claude "what did this branch do?" | Plain-English summary of recent commit history |
| git diff main | claude "are there any breaking changes?" | Identifies API/interface breaks in a branch diff |
| claude "resolve the merge conflict in src/api.ts" | Reads conflict markers and writes a merged version |
| git blame src/auth.ts | claude "why does this rate limit exist?" | Traces code history to find the original intent |
| claude "write a changelog from git log since v2.1.0" | Generates a user-facing CHANGELOG from commit history |
1. Writing Commit Messages
Stage your changes first, then pipe the diff to Claude:
# Stage what you want to commit
git add src/auth.ts src/middleware/rate-limit.ts
# Generate a commit message
git diff --staged | claude "write a conventional commit message for these changes.
Use the format: type(scope): subject\n\nbody explaining WHY not WHAT."
Claude reads the actual diff — not just file names — and writes a message that captures the purpose. Typical output:
feat(auth): add per-user rate limiting with Redis sliding window
Replace global rate limit (100 req/min shared) with per-user limits
(200 req/min per authenticated user, 20 req/min for anonymous).
Fixes #412 — heavy users were triggering limits for everyone else.
For more control, add a constraint: claude "write a commit message, 72 char subject line max, no bullet points in body".
2. PR Descriptions from Branch Diffs
Before opening a PR, generate a description from the full branch diff:
git fetch origin
git diff origin/main..HEAD | claude "write a PR description with:
- Summary (2-3 sentences)
- What changed (bulleted, by feature area not by file)
- Test plan
- Any breaking changes"
Claude groups changes by feature area rather than file-by-file, which makes PR descriptions readable for reviewers unfamiliar with the codebase.
3. Resolving Merge Conflicts
When git marks a file with conflict markers, ask Claude to resolve it:
claude "resolve the merge conflict in src/api/routes.ts.
HEAD has the new authentication middleware.
The incoming branch adds the /v2 route prefix.
Both changes should be preserved — don't drop either."
<<<<<<< HEAD, =======, >>>>>>>), understands the intent of each side, and writes a merged version. Give it context about which side has the correct business logic — it can't always infer product intent from code alone.
For multiple conflicted files at once:
# See all conflicted files
git diff --name-only --diff-filter=U
# Ask Claude to resolve them all
claude "resolve all merge conflicts in these files: $(git diff --name-only --diff-filter=U | tr '\n' ' ').
Keep the changes from feature/payments on all pricing-related logic."
4. Investigating Code History
Use Claude to trace why a piece of code exists:
claude "use git log and git blame to find when the exponential backoff was
added to src/http/client.ts and what issue or PR it was addressing."
Claude runs git blame on the relevant lines, reads the full commit messages for each change, and synthesizes a history. This is the fastest way to answer "why does this work this way?" without reading through PR threads manually.
5. Generating Changelogs
Generate user-facing changelogs from git history:
git log v2.3.0..HEAD --oneline | claude "write a user-facing CHANGELOG entry.
Group changes as: New Features, Improvements, Bug Fixes, Breaking Changes.
Skip internal refactors and dependency bumps.
Write for end users, not developers."
For automated changelogs in CI, see the CI/CD workflow guide.
6. Pre-commit Review
Before committing, use Claude as a final review pass:
git diff --staged | claude "review these changes before I commit:
- Any obvious bugs?
- Anything that will break existing callers?
- Missing error handling?
- Tests needed?
Be concise — one line per issue."
This catches common mistakes (forgotten debug logs, missing null checks, API signature changes) faster than manually re-reading the diff.
7. Branch Planning
Plan a complex feature branch before writing code:
claude "I need to add WebSocket support to the existing HTTP API in src/server/.
Look at the current structure and suggest a branch strategy:
- How many PRs to split this into?
- What order (dependencies)?
- What should each PR's scope be?"
Frequently Asked Questions
Can Claude Code write git commit messages automatically?
Yes. Stage your changes, then: git diff --staged | claude "write a conventional commit message". Claude reads the diff, identifies the type of change (feat/fix/refactor), and writes a message explaining the why, not just the what.
How do I resolve merge conflicts with Claude Code?
Ask directly: claude "resolve the merge conflict in src/auth.ts — keep the rate limiting from HEAD, integrate the new session logic from the incoming branch". Claude reads both conflict sides and merges them. Give it context about which side has the right business logic.
Can Claude Code summarize a git diff in plain English?
Yes. git diff main..feature | claude "summarize what changed and why". It groups changes by feature area (not file by file) and identifies breaking changes. Useful for writing PR descriptions quickly.
Does Claude Code integrate with git hooks?
Yes. You can call Claude from any git hook via the shell. A common pattern: add a commit-msg hook that pipes the staged diff to Claude and suggests a message if the message is too short. See the best practices guide for hook configuration examples.
Can Claude Code do interactive rebase?
Not directly — git rebase -i requires an interactive editor Claude can't control. But Claude can plan a rebase: claude "review my last 10 commits and suggest what to squash, what to split, and the right order for review". You execute the plan, Claude writes new commit messages after the squash.