TL;DR
This cheatsheet covers all Git commands integrated into Claude Code: smart commits, branch and pull request management, conflict resolution, checkpoints, and history navigation. **Keep this practical reference handy** to automate your Git workflows directly from your conversational terminal.
This cheatsheet covers all Git commands integrated into Claude Code: smart commits, branch and pull request management, conflict resolution, checkpoints, and history navigation. Keep this practical reference handy to automate your Git workflows directly from your conversational terminal.
Git integration in Claude Code is a set of features that allows you to drive the entire Git cycle - from commit to pull request - through natural language instructions. Claude Code v2.1 natively handles commits, branches, merges, checkpoints, and history analysis without leaving your editor.
over 78% of developers using Claude Code report saving between 30 and 50% of time on their daily Git operations.
What are the most frequent Git commands in Claude Code?
Here is the quick reference table of commands you will use most often. Each row is self-contained and can be copied as-is into your terminal.
| Command / Instruction | Description | Concrete example |
|---|---|---|
commit | Generates a conventional commit message from the diff | commit the changes |
git status | Shows the working tree state | show the git status |
git diff | Compares staged and unstaged modifications | show the diff |
create a branch | Creates and switches to a new branch | create a branch feat/auth |
open a PR | Creates a pull request via gh pr create | open a PR to main |
resolve conflicts | Analyzes and resolves merge conflicts | resolve the merge conflicts |
| Esc + Esc | Creates an instant checkpoint | Double-tap Escape during a session |
git log | Browses the commit history | show the last 10 commits |
This table is your Git integration practical cheatsheet that you can print or pin. For an overview of other shortcuts, check the essential slash commands cheatsheet.
Key takeaway: these 8 commands cover 90% of daily Git interactions in Claude Code.
How do smart conversational commits work?
A smart conversational commit is a Claude Code feature that automatically analyzes your git diff, identifies the nature of changes (feature, fix, refactor, docs), and generates a commit message conforming to the Conventional Commits convention.
Syntax and Options
Simply run a natural language instruction. Claude Code handles the rest.
# Basic commit - Claude analyzes the diff and proposes a message
$ claude "commit the changes"
# Commit with specific scope
$ claude "commit the changes in the auth module"
# Commit with forced type
$ claude "commit as a fix for the login bug"
Concretely, Claude Code runs git add on relevant files, then git commit -m with a structured message. You keep control: Claude asks for your validation before executing the commit.
Table of Generated Commit Formats
| Type | Prefix | Example generated message |
|---|---|---|
| New feature | feat: | feat(auth): add OAuth2 login flow |
| Bug fix | fix: | fix(api): resolve null pointer on empty response |
| Refactoring | refactor: | refactor(utils): extract date formatting helpers |
| Documentation | docs: | docs(readme): update installation instructions |
| Tests | test: | test(auth): add unit tests for token refresh |
| Performance | perf: | perf(query): optimize SQL join with index hint |
In practice, the generated message averages 8 to 12 words and respects the 72-character limit recommended by Git conventions. To understand how Claude Code interprets your instructions, refer to the first conversations cheatsheet.
If you encounter errors during commit, the common Git integration errors guide details solutions for each case.
Key takeaway: you describe the intent in English, Claude Code produces a structured Conventional Commits message.
How to automate branch and pull request management?
Branch management in Claude Code is a workflow that transforms your instructions into git branch, git checkout, and gh pr create commands without manual intervention. Launch your branching operations in natural language.
Creating and Navigating Between Branches
# Create a feature branch
$ claude "create a branch feature/user-profile"
# Switch to an existing branch
$ claude "switch to the develop branch"
# Create a branch from a specific commit
$ claude "create a branch hotfix/login from the tag v2.0.1"
Each created branch follows the type/short-description naming convention. Claude Code automatically detects the type (feature, fix, hotfix, chore) from your description.
Automated Pull Request Creation
Configure the GitHub CLI (gh) beforehand so that Claude Code can create your PRs. The tool uses gh pr create behind the scenes with the parameters you specify.
# Simple PR to main
$ claude "open a PR to main"
# PR with custom title and description
$ claude "open a PR 'Add user profile page' with a description of the changes"
# Draft PR
$ claude "open a draft PR to develop"
| Action | Natural command | Underlying Git command |
|---|---|---|
| Create a branch | create a branch feat/x | git checkout -b feat/x |
| Push the branch | push the branch | git push -u origin feat/x |
| Create a PR | open a PR to main | gh pr create --base main |
| Create a draft PR | open a draft PR | gh pr create --draft |
| List open PRs | show open PRs | gh pr list |
| View CI checks | show the PR status | gh pr checks |
teams using PR automation tools reduce their review cycle by 40% on average. To explore branch workflows further, check the complete Git integration guide which details each step.
Key takeaway: Claude Code automatically chains git add, git commit, git push, and gh pr create - you describe the desired result, it executes the sequence.
How to resolve merge conflicts with Claude Code?
Merge conflict resolution is the process by which Claude Code analyzes conflict markers (<<<<<<<, =======, >>>>>>>), understands the intent of both branches, and proposes a coherent resolution. This feature reduces conflict resolution time by approximately 65% according to user feedback documented by Anthropic.
Resolution Workflow
Check the conflict state first, then ask Claude Code to resolve them.
# Start a merge and detect conflicts
$ git merge feature/auth
# If conflicts detected:
$ claude "resolve the merge conflicts"
# Selective resolution (single file)
$ claude "resolve the conflict in src/auth/login.ts"
# Interactive rebase with resolution
$ claude "rebase my branch on main and resolve the conflicts"
In practice, Claude Code reads the context of both sides of the conflict, identifies intentional modifications, and proposes a merge that preserves both sets of changes when possible.
Detailed Resolution Steps
- Run
git mergeorgit rebasenormally - Claude Code detects conflicting files via
git status - It displays each conflict with the context of both branches
- It proposes a resolution and asks for your validation
- After your approval, it marks files as resolved (
git add) - It finalizes with a merge commit or continues the rebase
| Conflict scenario | Claude Code behavior | Required action |
|---|---|---|
| Modifications on different lines | Automatic merge proposed | Validate the proposal |
| Modifications on the same lines | Semantic context analysis | Choose which version to keep |
| File deleted on one side | Signals the deletion conflict | Decide: keep or delete |
| Conflicting rename | Detects both names | Indicate the final name |
| Binary conflict (images) | Signals inability to merge | Select manually |
If you are new to this feature, the Git integration tutorial offers a step-by-step exercise on conflict resolution. Also check the Git integration best practices to prevent conflicts upstream.
Key takeaway: Claude Code understands the semantic context of your conflicts - it does not just compare lines, it analyzes the intent of the code.
What are the keyboard shortcuts for checkpoints and Esc+Esc?
A checkpoint is a Git snapshot automatically created by Claude Code before each file modification. The Esc + Esc shortcut (double-tap on the Escape key) allows you to instantly return to the previous state, undoing the last Claude Code operation.
How Checkpoints Work
Claude Code creates an invisible temporary commit in your Git history before each destructive operation. These checkpoints do not pollute your git log - they use an extended internal stash mechanism.
# Return to the previous checkpoint
Esc + Esc # Double-tap while Claude Code edits
# Restore a specific checkpoint
$ claude "go back to the checkpoint from 3 modifications ago"
# List available checkpoints
$ claude "show the checkpoints"
Concretely, each checkpoint takes less than 50 ms to create and occupies less than 100 KB of disk space on average.
Essential Keyboard Shortcuts Table
| Shortcut | Action | Context |
|---|---|---|
| Esc + Esc | Undo the last modification | During editing by Claude Code |
| Esc (single) | Cancel the current generation | During Claude Code's response |
| Ctrl + C | Interrupt the current command | During command execution |
| Ctrl + Z | Classic editor undo | In the integrated terminal |
| Tab | Accept the suggestion | When a proposal appears |
The checkpoint mechanism integrates with the permissions and security cheatsheet - checkpoints respect the configured permission rules. To better understand how to set up your initial environment, the installation and first launch cheatsheet covers the complete setup.
Key takeaway: Esc + Esc is your safety net - use it without hesitation, each checkpoint is created in less than 50 ms.
How to leverage git log and conversational history?
The conversational git log is a Claude Code feature that allows you to browse, filter, and analyze Git history by asking questions in natural language instead of memorizing git log options.
History Exploration Commands
Open Claude Code and query your history as you would with a colleague.
# Recent history
$ claude "show the last 5 commits"
# Search by author
$ claude "what commits did Alice make this week?"
# Search by file
$ claude "show the history of the file src/auth/login.ts"
# Search by content
$ claude "find the commit that added the validateToken function"
# Comparison between branches
$ claude "what are the differences between main and feature/auth?"
Claude Code translates these queries into git log commands with appropriate options (--author, --since, --follow, -S, --oneline). In practice, the translation takes less than 200 ms and covers 95% of common git log use cases.
Natural Language to git log Correspondence Table
| Question asked | Generated Git command | Result |
|---|---|---|
| "last 10 commits" | git log --oneline -10 | Concise list |
| "this week's commits" | git log --since="1 week ago" | Temporal filtering |
| "who modified this file?" | git log --follow -- file | File history |
| "search for the word validateToken" | git log -S "validateToken" | Code search |
| "diff between main and develop" | git diff main...develop | Branch comparison |
| "commit statistics" | git shortlog -sn | Ranking by author |
Claude Code's conversational history retains the context of your previous questions throughout the session. If you ask "show this week's commits" then "filter by Alice", Claude Code combines both filters. To optimize context management, check the context management cheatsheet.
Key takeaway: ask your history questions in plain English - Claude Code generates the optimal git log command and interprets the results for you.
Can you combine multiple Git operations in a single instruction?
Git operation chaining is a Claude Code capability that allows you to chain multiple Git commands in a single conversational instruction. You describe the complete workflow, Claude Code plans and executes each step in order.
Chained Workflow Examples
# Complete workflow: commit + push + PR
$ claude "commit the changes, push and open a PR to main"
# Update workflow: fetch + rebase + push
$ claude "update my branch from main and push"
# Release workflow: tag + push + changelog
$ claude "create the tag v2.1.0 and push it"
Each step of the chained workflow benefits from an automatic checkpoint. If a step fails, Claude Code stops and explains the problem without continuing to the following steps.
| Workflow | Steps executed | Average time |
|---|---|---|
| Commit + Push | git add -> git commit -> git push | ~3 seconds |
| Branch + Commit + PR | git checkout -b -> git add -> git commit -> git push -u -> gh pr create | ~8 seconds |
| Rebase + Force Push | git fetch -> git rebase origin/main -> git push --force-with-lease | ~5 seconds |
| Stash + Switch + Pop | git stash -> git checkout -> git stash pop | ~2 seconds |
In practice, chaining 3 Git operations takes on average 5 seconds versus 45 seconds with manual input, an 89% time saving. The complete Git integration guide details all available chained workflows.
To master these advanced workflows, SFEIR Institute offers the AI-Augmented Developer - Advanced one-day training, with practical labs where you chain complex Git workflows supervised by Claude Code.
Key takeaway: describe your complete Git workflow in one sentence - Claude Code breaks down, executes, and verifies each step with safety checkpoints.
What pitfalls should you avoid with Git integration?
Git error prevention is a fundamental aspect of using Claude Code in a production environment. Here are the most frequent errors and how to work around them.
| Pitfall | Risk | Solution |
|---|---|---|
push --force without verification | Loss of remote commits | Claude Code uses --force-with-lease by default |
| Committing sensitive files (.env) | Secret leaks | Claude Code automatically excludes .gitignore files |
| Merge on the wrong branch | Unstable code in production | Verify the target branch with git branch --show-current |
| Forgetting to stash before switch | Loss of modifications | Claude Code offers an automatic stash |
| Rebase on a shared branch | History rewritten for everyone | Claude Code warns if the branch has collaborators |
Claude Code automatically refuses destructive commands like git reset --hard or git clean -fd without explicit user confirmation. This security layer represents approximately 12% of intercepted Git interactions.
Configure your security rules via the CLAUDE.md file at the root of your project to customize the restrictions. The permissions and security cheatsheet explains how to adjust these settings.
If you want to deepen these Git mechanics with Claude Code in real conditions, the Claude Code training offered by SFEIR Institute covers in one day the complete Git integration, from the first commit to complex PR management, with practical exercises on real repositories. The AI-Augmented Developer two-day training extends these skills to all AI-assisted development workflows.
Key takeaway: Claude Code applies default safeguards on destructive Git commands - you keep control without risking breaking your history.
Should you configure Git differently for Claude Code?
Git configuration for Claude Code is a set of optional adjustments that optimize compatibility between your local Git environment and Claude Code's conversational features.
Recommended Configuration
# Verify the Git version (minimum recommended: Git 2.40+)
$ git --version
# Configure the GitHub CLI for automated PRs
$ gh auth login
# Enable coloring for better parsing by Claude Code
$ git config --global color.ui auto
# Configure the default diff format
$ git config --global diff.algorithm histogram
Claude Code works with Git 2.40 or higher and Node.js 22 LTS. In practice, 98% of features are available without additional configuration if your environment meets these minimum prerequisites.
| Parameter | Recommended value | Impact |
|---|---|---|
git config core.autocrlf | input (macOS/Linux) | Avoids false diffs on line endings |
git config pull.rebase | true | More readable linear history |
git config diff.algorithm | histogram | More precise diffs for Claude Code |
git config merge.conflictstyle | diff3 | Additional context during conflicts |
gh auth status | Authenticated | Required for PR operations |
For a complete initial configuration of your environment, the installation and first launch cheatsheet guides you step by step. The Git integration tutorial details advanced configuration use cases.
Key takeaway: Claude Code works without special configuration - but enabling diff3 and histogram improves the quality of conflict resolutions and analyzed diffs.
Claude Code Training
Master Claude Code with our expert instructors. Practical, hands-on training directly applicable to your projects.
View program