Cheatsheet13 min read

Git Integration - Cheatsheet

SFEIR Institute

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 / InstructionDescriptionConcrete example
commitGenerates a conventional commit message from the diffcommit the changes
git statusShows the working tree stateshow the git status
git diffCompares staged and unstaged modificationsshow the diff
create a branchCreates and switches to a new branchcreate a branch feat/auth
open a PRCreates a pull request via gh pr createopen a PR to main
resolve conflictsAnalyzes and resolves merge conflictsresolve the merge conflicts
Esc + EscCreates an instant checkpointDouble-tap Escape during a session
git logBrowses the commit historyshow 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

TypePrefixExample generated message
New featurefeat:feat(auth): add OAuth2 login flow
Bug fixfix:fix(api): resolve null pointer on empty response
Refactoringrefactor:refactor(utils): extract date formatting helpers
Documentationdocs:docs(readme): update installation instructions
Teststest:test(auth): add unit tests for token refresh
Performanceperf: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"
ActionNatural commandUnderlying Git command
Create a branchcreate a branch feat/xgit checkout -b feat/x
Push the branchpush the branchgit push -u origin feat/x
Create a PRopen a PR to maingh pr create --base main
Create a draft PRopen a draft PRgh pr create --draft
List open PRsshow open PRsgh pr list
View CI checksshow the PR statusgh 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

  1. Run git merge or git rebase normally
  2. Claude Code detects conflicting files via git status
  3. It displays each conflict with the context of both branches
  4. It proposes a resolution and asks for your validation
  5. After your approval, it marks files as resolved (git add)
  6. It finalizes with a merge commit or continues the rebase
Conflict scenarioClaude Code behaviorRequired action
Modifications on different linesAutomatic merge proposedValidate the proposal
Modifications on the same linesSemantic context analysisChoose which version to keep
File deleted on one sideSignals the deletion conflictDecide: keep or delete
Conflicting renameDetects both namesIndicate the final name
Binary conflict (images)Signals inability to mergeSelect 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

ShortcutActionContext
Esc + EscUndo the last modificationDuring editing by Claude Code
Esc (single)Cancel the current generationDuring Claude Code's response
Ctrl + CInterrupt the current commandDuring command execution
Ctrl + ZClassic editor undoIn the integrated terminal
TabAccept the suggestionWhen 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 askedGenerated Git commandResult
"last 10 commits"git log --oneline -10Concise list
"this week's commits"git log --since="1 week ago"Temporal filtering
"who modified this file?"git log --follow -- fileFile history
"search for the word validateToken"git log -S "validateToken"Code search
"diff between main and develop"git diff main...developBranch comparison
"commit statistics"git shortlog -snRanking 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.

WorkflowSteps executedAverage time
Commit + Pushgit add -> git commit -> git push~3 seconds
Branch + Commit + PRgit checkout -b -> git add -> git commit -> git push -u -> gh pr create~8 seconds
Rebase + Force Pushgit fetch -> git rebase origin/main -> git push --force-with-lease~5 seconds
Stash + Switch + Popgit 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.

PitfallRiskSolution
push --force without verificationLoss of remote commitsClaude Code uses --force-with-lease by default
Committing sensitive files (.env)Secret leaksClaude Code automatically excludes .gitignore files
Merge on the wrong branchUnstable code in productionVerify the target branch with git branch --show-current
Forgetting to stash before switchLoss of modificationsClaude Code offers an automatic stash
Rebase on a shared branchHistory rewritten for everyoneClaude 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.

# 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.

ParameterRecommended valueImpact
git config core.autocrlfinput (macOS/Linux)Avoids false diffs on line endings
git config pull.rebasetrueMore readable linear history
git config diff.algorithmhistogramMore precise diffs for Claude Code
git config merge.conflictstylediff3Additional context during conflicts
gh auth statusAuthenticatedRequired 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.


Recommended training

Claude Code Training

Master Claude Code with our expert instructors. Practical, hands-on training directly applicable to your projects.

View program