Claude Code git integration: auto-commit, branch per task, and clean history without thinking
One of Claude Code's most underrated features is how it handles git. Most developers treat Claude Code as a code editor with AI — but if you configure it right, it becomes an autonomous git operator that commits, branches, and cleans up after itself.
Here's how I set mine up.
The default behavior (and why it's annoying)
By default, Claude Code does not commit anything. It makes changes to files, shows you a diff, and stops. You have to manually run git add and git commit.
For quick experiments this is fine. For multi-file refactors across 20 files, it's a workflow killer.
Setting up auto-commit in CLAUDE.md
Add this to your project CLAUDE.md:
## Git workflow
- After completing any task, run: git add -A && git commit -m "[task description]"
- Use conventional commits: feat:, fix:, refactor:, docs:
- Never commit node_modules, .env, or build artifacts
- If the task spans multiple files, commit all at once with a clear summary message
Now Claude Code will commit after every completed task. Your git log becomes a readable history of what actually happened.
Branch per task pattern
For bigger changes, I use this pattern in CLAUDE.md:
## Branch strategy
- Before starting any feature task, create a branch: git checkout -b task/[short-description]
- Complete the task on that branch
- Do not merge — leave the branch for human review
- Report the branch name when done
This gives you:
- A clean main branch that's never broken
- One branch per Claude session
- Easy rollback (just delete the branch)
- Human review before anything merges
Commit message quality
The default Claude commit messages are... fine. "Updated auth.js" is not helpful.
Add this to CLAUDE.md to improve them:
## Commit messages
Write commit messages that explain WHY, not what:
- Bad: "Updated auth.js"
- Good: "fix: redirect to /login when session expires instead of blank screen"
Always include the affected component and the user-facing behavior change.
Custom /commit slash command
If you use Claude Code's custom slash commands, add this as .claude/commands/commit.md:
Review all unstaged changes in this repo. Group related changes logically.
For each group:
1. Stage the files: git add [files]
2. Write a conventional commit message explaining the change
3. Commit: git commit -m "[message]"
After all commits, run git log --oneline -10 to show what was committed.
Do not commit package-lock.json or any .env files.
Now you can run /commit at any point and Claude Code will review your entire working tree and create a clean, logical commit history.
Handling merge conflicts
When you have merge conflicts, tell Claude Code:
I have merge conflicts in these files. Resolve them by keeping the intent of both changes where possible. If you can't reconcile, keep the incoming change and add a TODO comment.
Claude Code reads both versions, understands the intent, and resolves conflicts that would take you 20 minutes to sort through.
The full git workflow setup
Here's my complete git section in CLAUDE.md:
## Git rules
1. Never commit: .env, node_modules, *.log, dist/, .DS_Store
2. Always use conventional commits (feat/fix/refactor/docs/chore)
3. Commit after every completed task, not after every file change
4. Branch for features: git checkout -b feat/[name]
5. Branch for fixes: git checkout -b fix/[name]
6. Leave branches unmerged — humans review and merge
7. Commit message format: "type(scope): what changed and why"
Rate limits kill your git flow
The worst thing that can happen mid-refactor: Claude Code hits a rate limit right before it commits. You have 20 files changed, no commit, and you're staring at the "API overloaded" message.
I fixed this by pointing Claude Code at a proxy:
export ANTHROPIC_BASE_URL=https://simplylouie.com
SimplyLouie removes rate limits for $2/month — simplylouie.com. The API is identical, same Claude models, just no rate limiting.
The result
With this setup:
- Every Claude session leaves a clean git trail
- You can see exactly what Claude did and why
- Rollback is
git checkoutaway - Your team can review Claude's work in pull requests like any other contributor
Claude Code isn't just an AI that writes code. Configured right, it's a junior developer who commits clean, branches appropriately, and explains their work. You just have to tell it how.
Using Claude Code in production? What's your git workflow look like? Drop it in the comments.
Top comments (0)