Claude Code is Anthropic's official AI coding agent, used by developers at companies from startups to Fortune 500. Learn more →

Claude Code Guide

How to Use Claude Code for Git Commits

Stop writing commit messages manually. Learn how Claude Code generates meaningful commits, stages changes intelligently, and keeps your git history clean.

Updated February 10, 2026 · 11 min read

Type /commit in Claude Code and it handles everything — it reads your diffs, stages the right files, and generates a descriptive commit message for you to approve. No more writing "fix bug" or "update styles." Claude analyzes what you actually changed and explains the why, not just the what.

This guide covers the full git workflow in Claude Code: the /commit command, intelligent staging, custom commit conventions, branch management, and how to chain operations like commit-push-PR into a single step.

What Is Claude Code Git Integration?

Claude Code has built-in git awareness. It can:

The /commit slash command is the fastest way to commit, but Claude handles any git operation you describe in plain English. You can also create custom slash commands like /commit-push-pr that chain multiple git operations together.

New to Claude Code? Get the Free Blueprint first to see the basics, then come back for git workflows.

1 The /commit Workflow

The simplest way to commit with Claude Code:

/commit

That's it. Claude:

  1. Runs git status to see what's changed
  2. Runs git diff to analyze the actual changes
  3. If no files are staged, Claude automatically stages the appropriate files
  4. Generates a commit message based on what it sees
  5. Shows you the message for approval
  6. Creates the commit when you confirm

A key behavior: if you have not manually staged anything, Claude reviews your changes and stages files automatically. This means you can go straight from coding to /commit without running git add first.

The generated message follows conventional commit format by default:

feat: add user authentication with JWT tokens

- Implement login and logout endpoints
- Add JWT token generation and validation
- Create middleware for protected routes
- Add refresh token support
Review before confirming Claude shows you the proposed message. You can accept it, modify it, or ask Claude to rewrite it with different emphasis.

2 Staging Changes

Before committing, you need staged changes. Claude handles staging intelligently.

Stage Everything

Stage all my changes

Claude runs git add -A and confirms what was staged.

Stage Specific Files

Stage only the files in src/auth/

Claude stages just those files, leaving others unstaged for a separate commit.

Stage by Type

Stage the JavaScript files but not the tests

Claude understands file patterns and stages accordingly.

Review Before Staging

Show me what would be staged, then let me choose

Claude shows you the changes and lets you decide what to include.

3 Customizing Commit Messages

You can guide Claude's commit messages with context:

Provide Context

Commit these changes. This fixes the login bug reported in issue #42.

Claude incorporates the context into the message:

fix: resolve login failure on Safari browsers (#42)

- Handle Safari's stricter cookie policy
- Add SameSite=None for cross-origin requests
- Update session handling for mobile Safari

Request a Specific Style

Commit with a short one-line message, no body

Claude produces: fix: resolve Safari login issue

I documented my full Claude Code workflow — including git automation — in a free guide you can grab here.

Follow Your Project's Conventions

Add commit conventions to your CLAUDE.md file:

# Commit Message Format

- Use imperative mood ("Add feature" not "Added feature")
- Start with type: feat, fix, docs, style, refactor, test, chore
- Keep first line under 72 characters
- Reference issue numbers in the body
- Sign off with team initials

Claude follows these conventions automatically in future commits.

Custom Git Slash Commands

Slash commands are Markdown files stored in .claude/commands/ (project-level) or ~/.claude/commands/ (personal). You can create custom commands that chain git operations together.

Create a /commit-push-pr Command

Create the file .claude/commands/commit-push-pr.md:

Review all changes, then:
1. Stage the appropriate files
2. Create a commit with a descriptive conventional commit message
3. Push to the current branch
4. Create a pull request with a summary of the changes

Here is the current git status:
!git status
!git diff

Lines starting with ! are executed before Claude processes the command. Claude sees the output of git status and git diff and uses it to generate the commit message and PR description.

Now you can run /commit-push-pr from Claude Code to handle the entire workflow in one step.

4 Common Git Operations

Beyond committing, Claude handles your entire git workflow.

Create a Branch

Create a branch for adding user profile features

Claude creates feature/user-profile and switches to it.

View History

Show me the last 5 commits with their changes

Claude runs git log with relevant flags and summarizes each commit.

Check Status

What files have I changed since my last commit?

Claude shows modified, staged, and untracked files with helpful context.

Discard Changes

Discard my changes to config.js, keep everything else

Claude runs git checkout config.js safely.

Stash Changes

Stash my current changes with a descriptive message

Claude creates a named stash you can find later.

Amend Last Commit

Add these changes to my last commit without changing the message

Claude uses git commit --amend --no-edit appropriately.

Be careful with history-changing operations Amending, rebasing, and force-pushing can cause problems if others have pulled your changes. Claude will warn you, but always verify before modifying pushed commits.

Use Git Worktrees for Parallel Tasks

If you need multiple Claude Code sessions working on different branches simultaneously, git worktrees let each session have isolated files while sharing git history:

# Create a worktree for a new feature
git worktree add ../project-feature-a -b feature-a

# Run Claude Code in the worktree
cd ../project-feature-a && claude

Each worktree maintains independent file state, so Claude instances cannot interfere with each other when working on different tasks.

Commit Message Best Practices

Claude follows these by default, but understanding them helps you guide better messages:

PrincipleGood ExampleBad Example
Explain why, not whatfix: prevent race condition in user syncfix: change line 42
Use imperative moodAdd validation for email inputAdded validation for email
Keep first line shortfeat: add dark mode togglefeat: add dark mode toggle to the settings page with persistence
Reference issuesfix: resolve timeout error (#123)fix: resolve timeout error
Use conventional typesrefactor: extract auth logiccleanup: auth stuff

Conventional Commit Types

Real Command Examples

Copy these for your workflows:

Complete Feature Workflow

# Start the feature
Create a branch called feature/user-preferences

# After making changes
Stage the preference-related files and commit with a message explaining the new user preferences system

# Multiple logical commits
Stage only the database migration and commit as "feat: add preferences table"
Stage the API endpoints and commit as "feat: add preference CRUD endpoints"
Stage the frontend changes and commit as "feat: add preferences UI"

Bug Fix Workflow

# Investigate
Show me recent commits that touched the payment module

# Fix and commit
Stage my fix and commit with a message explaining this resolves the double-charge bug from issue #89

# Verify
Show me the diff of my last commit to verify the fix

Cleanup Workflow

# Review uncommitted work
Show me all my unstaged changes grouped by file type

# Selective commits
Stage and commit the documentation changes separately from code changes

# Verify clean state
Confirm there are no uncommitted changes

Common Mistakes

  1. Committing everything at once: Make atomic commits. Ask Claude to "stage only the authentication changes" instead of staging everything.
  2. Accepting vague messages: If Claude generates "update files," ask it to be more specific. Give it context about why you made the changes.
  3. Forgetting to review: Always check the proposed commit message before confirming. Claude is good but not perfect.
  4. Not using CLAUDE.md: Document your commit conventions in CLAUDE.md. Claude will follow them consistently across sessions.
  5. Amending pushed commits: Be careful with --amend on commits that have been pushed. Claude warns you, but pay attention.

FAQ

Does Claude push automatically after committing?

No. Claude commits locally but does not push unless you explicitly ask. This gives you a chance to review before sharing changes. Ask "commit and push" if you want both.

Can I customize the commit message format?

Yes. Add your format preferences to CLAUDE.md. For example, specify that you want Jira ticket numbers, emoji prefixes, or a specific structure. Claude adapts to your style.

What if I don't like the generated message?

Tell Claude what to change: "Make it shorter," "Focus on the security implications," or "Use our team's format." Claude rewrites until you're satisfied.

Does /commit handle merge commits?

For simple merges, yes. For complex merge conflicts, Claude helps you resolve conflicts first, then creates an appropriate merge commit message.

Can Claude write commit messages for past commits?

Not directly, but you can ask Claude to analyze a commit and suggest a better message, then use git commit --amend to update it (only for unpushed commits).

Free: The AI Growth Breakdown

See how one business went from 0 to 600 daily visitors in 14 days using AI. The exact tools and results.

Get the Free Breakdown →

Keep reading