Claude Code Git Workflow Guide
Git is Claude Code's native language
Claude Code runs in your terminal, which means it has full access to Git. Not through a plugin or extension, through the actual git CLI. It can read diffs, write commits, create branches, resolve conflicts, and push to remotes. Every Git operation you do manually, Claude Code can do with better context.
This isn't about replacing your Git knowledge. It's about eliminating the friction between "I finished the code" and "it's committed, pushed, and ready for review." That friction, writing commit messages, staging the right files, creating PRs with useful descriptions, is where most developers lose time. Claude Code handles it.
Smart commits
The most immediate win is commit messages. Claude Code reads the diff, understands what changed and why, and writes a message that actually describes the change:
Commit the current changes with a descriptive message.
Claude Code runs git diff --cached (or git diff if nothing is staged), analyzes the changes, and produces a commit message like:
Fix race condition in WebSocket reconnection handler
The previous implementation could fire multiple reconnection
attempts simultaneously when the connection dropped during
a pending message flush. Added a mutex lock around the
reconnect cycle and a backoff timer to prevent thundering herd.
Compare that to the fix bug or update stuff messages that happen when you're tired and just want to commit. Claude Code writes the message you'd write if you had unlimited patience.
Commit conventions
If your team uses Conventional Commits, Angular format, or any other convention, tell Claude Code once in your CLAUDE.md:
## Git conventions
- Use Conventional Commits: type(scope): description
- Types: feat, fix, refactor, docs, test, chore, perf
- Scope is the module name (auth, api, ui, db)
- Description under 72 chars, imperative mood
Every commit Claude Code creates will follow that convention. No linting failures, no rejected commits, no "please fix the commit message" comments on PRs.
Branch management
Claude Code handles branch operations with awareness of your project's branching strategy:
Create a feature branch for adding email verification to the auth flow.
Claude Code will create feat/email-verification (or whatever pattern matches your convention), switch to it, and confirm the working tree is clean. If you have uncommitted changes, it'll ask whether to stash, commit, or carry them forward.
For more complex branching:
I need to backport the security fix from main to the release/2.4 branch.
Cherry-pick commits abc123 and def456.
Claude Code handles the cherry-pick, resolves any conflicts using its understanding of both branches, and presents the result for your review.
Pull request creation
Creating a PR is where Claude Code's contextual understanding pays off most. It doesn't just list the files changed, it explains the purpose, the approach, and the testing done:
Create a PR for this branch against main.
Claude Code runs git log main..HEAD to see all commits, git diff main...HEAD to see the full changeset, and produces a PR with:
- A concise title under 72 characters
- A summary explaining why the change was made
- A list of key changes with context
- Testing notes based on what it observed during the session
- Any relevant issue references from commit messages
If you use GitHub, Claude Code creates the PR directly via the gh CLI. The PR is ready for review the moment Claude Code finishes, no editing the auto-generated template, no copying issue numbers, no writing "## What changed" for the fifth time today.
Merge conflict resolution
Merge conflicts are where developers lose the most time relative to the value produced. Reading both sides, understanding the intent, choosing the right resolution, it's mentally taxing and error-prone.
Claude Code resolves conflicts by reading the actual code, not just the conflict markers:
Merge main into this branch and resolve any conflicts.
When Claude Code encounters a conflict, it reads both versions, checks the git log to understand what each side was trying to accomplish, and produces a resolution that preserves both intents. If the intents genuinely conflict (two people edited the same function for different reasons), Claude Code explains the situation and asks you to decide.
This is fundamentally different from how merge tools work. VS Code's merge editor shows you "current" and "incoming", but doesn't know why each change was made. Claude Code reads the commit messages, the surrounding code, and the broader context to make an informed resolution.
Complex rebases
Interactive rebases are where things get hairy. Claude Code can help plan them:
I need to clean up this branch before PR review. There are 12 commits
including 3 "fix typo" commits and 2 "WIP" commits. Suggest a rebase
plan that squashes related commits into logical units.
Claude Code will analyze the commit history, group related changes, and suggest a rebase plan. You execute it, Claude Code doesn't run interactive rebases itself, but the plan saves you from staring at a commit list trying to figure out what goes with what.
Code review via Git
Claude Code can review code by reading Git diffs, giving you a reviewer's perspective before you push:
Review the changes on this branch compared to main.
Focus on security, performance, and API design.
Claude Code runs git diff main...HEAD, reads every changed file in context (not just the diff lines), and produces a structured review. It catches things that are hard to spot in a diff view:
- A new API endpoint that's missing authentication middleware
- A database query inside a loop that will cause N+1 problems at scale
- An error handler that swallows exceptions silently
- A type assertion that bypasses the type system without justification
This isn't a replacement for human code review: it's a pre-review that catches the mechanical issues so your human reviewers can focus on architecture and design decisions.
For teams, you can build a custom command that runs this review automatically before every push:
---
description: Pre-push code review
allowed-tools:
- Read
- Bash(git:*)
- Grep
---
Review all changes on the current branch vs main:
1. Run `git diff main...HEAD` to see the full changeset
2. Check each changed file for security, performance, and correctness issues
3. If any HIGH severity issues found, list them and recommend fixing before push
4. If only LOW/MEDIUM issues, note them but don't block
Git hooks integration
Claude Code respects your existing Git hooks. If you have pre-commit hooks running ESLint, Prettier, or type checks, Claude Code's commits go through the same pipeline. When a hook fails, Claude Code reads the error, fixes the issue, and retries.
You can also use Claude Code's own hooks system to add Git-aware automation:
- PreToolUse hook on Bash(git push):* Verify tests pass before allowing a push
- PostToolUse hook on Bash(git commit):* Log the commit to your daily notes
- PreToolUse hook on Bash(git checkout):* Warn if there are uncommitted changes
These hooks run inside Claude Code, complementing your repo's Git hooks. Together, they create a safety net that catches mistakes before they reach the remote.
Workflow: from code to merged PR
Here's what a complete Claude Code Git workflow looks like in practice:
- Start:
/startloads your project context and current branch status - Code: Write your feature with Claude Code's help
- Test: Claude Code runs your test suite and fixes failures
- Commit: Claude Code stages the right files and writes a descriptive commit
- Review: Claude Code reviews the branch diff and flags issues
- PR: Claude Code creates the PR with a complete description
- Address feedback: Claude Code reads PR review comments and applies fixes
- Merge: Once approved, Claude Code merges and cleans up the branch
Each step is one or two sentences of instruction. The entire flow from "code done" to "PR merged" takes minutes instead of the usual context-switching, message-writing, template-filling friction.
FAQ
Does Claude Code push to remote repositories automatically?
No. Claude Code never pushes to a remote unless you explicitly ask it to. This is a safety boundary, pushing is a destructive action that affects your team. Claude Code will prepare everything locally (commits, branches, tags) and wait for your instruction to push.
Can Claude Code work with GitLab or Bitbucket, not just GitHub?
Claude Code uses the git CLI directly, so it works with any Git remote, GitHub, GitLab, Bitbucket, self-hosted. For PR creation, it uses the gh CLI for GitHub. For other platforms, it can prepare the branch and provide instructions, or you can configure platform-specific CLIs.
How does Claude Code handle sensitive files in commits?
Claude Code avoids staging files that likely contain secrets, .env, credentials.json, private keys, and similar patterns. If you specifically ask it to commit such files, it warns you first. This built-in caution prevents the most common Git security mistake: accidentally committing secrets to a repository.
Your Git workflow should be frictionless, not an afterthought. Claudify ships with Git-aware commands, pre-push review hooks, and commit conventions built in. Install with npx create-claudify.
More like this
Ready to upgrade your Claude Code setup?
Get Claudify