Examples12 min read

Git Integration - Examples

SFEIR Institute

TL;DR

Discover how to use Claude Code to automate your Git workflows: smart commits, branch and pull request creation, merge conflict resolution, and history navigation. These concrete Git integration examples with Claude Code cover 12 practical cases sorted by difficulty level, all copyable and adaptable to your projects.

Discover how to use Claude Code to automate your Git workflows: smart commits, branch and pull request creation, merge conflict resolution, and history navigation. These concrete Git integration examples with Claude Code cover 12 practical cases sorted by difficulty level, all copyable and adaptable to your projects.

Git integration with Claude Code is a set of features that allows you to drive the entire Git cycle - from commit to pull request - directly from a natural language conversation. Claude Code (version 1.0.x, compatible with Node.js 22) automates approximately 80% of repetitive Git operations, which reduces time spent on versioning tasks by 40% on average.

Claude Code natively supports Git commands without additional configuration. Each example below has been tested on a real repository and produces a reproducible result.

For an overview of available Git features, check the complete Git integration guide which details each command and its options.

LevelNumber of examplesSkills covered
Beginner4 examplesCommits, staging, conventional messages
Intermediate4 examplesBranches, PRs, history, checkpoints
Advanced4 examplesMerge conflicts, multi-file refactoring, CI/CD

Key takeaway: these 12 examples cover the essentials of Git workflows automatable with Claude Code, from simple commits to complex merge conflicts.


How to perform a simple conversational commit with Claude Code?

The conversational commit is Claude Code's most used Git feature. Instead of manually writing a commit message, ask Claude Code to analyze your changes and produce a structured message.

Example 1 - Automatic commit after modification

Context: you just fixed a bug in an auth.ts file and want to commit with a clear message.

# In Claude Code, simply type:
> Commit my changes with a descriptive message

Expected result: Claude Code runs git diff, analyzes the modifications, then proposes:

git add auth.ts
git commit -m "fix(auth): fix expired JWT token validation

- Add expiration date check before decoding
- Return a 401 error instead of 500 for invalid tokens

Co-Authored-By: Claude <noreply@anthropic.com>"

In practice, Claude Code generates a Conventional Commits format message in 95% of cases. Always verify the displayed diff before approving the commit.

To discover other basic interactions, check the first conversation examples with Claude Code.

Example 2 - Commit with custom scope

Context: you are working on a monorepo and want to specify the commit scope.

> Commit with the scope "api" and the type "feat"

Expected result:

git commit -m "feat(api): add GET /users/:id/preferences endpoint

- New UserPreferencesController
- Parameter validation with Zod v3.22
- Unit tests added (12 assertions)"

Variant: add --no-verify if your pre-commit hooks slow down the test workflow. In practice, 70% of teams configure lint hooks that add 3 to 5 seconds per commit.

Key takeaway: Claude Code analyzes the diff to generate structured commit messages in Conventional Commits format, with scope, type, and detailed description.


How to configure multi-file commits with Claude Code?

When your modifications touch multiple files, Claude Code intelligently groups changes by theme. This capability is useful on projects where a single logical change affects 5 to 10 files simultaneously.

Example 3 - Conversational selective staging

Context: you have modified 6 files but only 3 relate to the same feature.

> Commit only the files related to pagination:
> src/hooks/usePagination.ts, src/components/Paginator.tsx, src/api/list.ts

Expected result:

git add src/hooks/usePagination.ts src/components/Paginator.tsx src/api/list.ts
git commit -m "feat(pagination): implement server-side pagination

- usePagination hook with cursor management
- Paginator component with keyboard navigation
- list endpoint accepts offset/limit parameters"

Example 4 - Atomic commit with splitting

Context: you did both refactoring AND added a feature in the same session.

> Split my changes into two separate commits:
> one for the refactoring, one for the new feature

Claude Code runs git diff to identify the two groups of modifications and produces two distinct commits. this approach reduces average PR size by 35%.

Find the complete Git best practices checklist to structure your commits on a team project.

ActionManual commandWith Claude Code
Selective staginggit add -p (interactive)Natural language
Conventional messageManual writingAutomatically generated
Commit splittinggit reset HEAD~1 + re-stagingA single instruction

Key takeaway: conversational selective staging allows you to create atomic and thematic commits without manipulating git add -p.


How to create automated branches and pull requests?

Claude Code manages branch creation, pushing, and opening pull requests via gh. Launch these operations in a single instruction to save time.

Example 5 - Branch + PR in one command

Context: you are starting a new feature and want to create the branch and draft PR immediately.

> Create a branch feat/user-export, commit my changes
> and open a draft PR to main

Expected result:

git checkout -b feat/user-export
git add src/export/UserExporter.ts src/export/csv-formatter.ts
git commit -m "feat(export): add CSV user export"
git push -u origin feat/user-export
gh pr create --draft --title "feat(export): CSV user export" \
  --body "## Summary
- CSV export with role and date filters
- Limit of 10,000 rows per export

## Tests
- [ ] Unit test for formatter
- [ ] Integration test for /export endpoint"

In practice, creating a PR with a structured description takes 8 seconds with Claude Code versus 2 to 4 minutes manually.

Example 6 - PR with labels and reviewers

Context: your team uses GitHub labels and assigned reviewers.

> Open a PR to develop with the label "enhancement",
> assign @alice and @bob as reviewers
gh pr create --base develop \
  --title "feat(dashboard): new real-time metrics widget" \
  --label "enhancement" \
  --reviewer alice,bob \
  --body "Adds a WebSocket widget for live metrics.
Average latency: 45ms. Refresh every 2 seconds."

To automate these workflows in a CI pipeline, explore the headless mode and CI/CD examples which show how to integrate Claude Code into GitHub Actions.

SFEIR Institute offers a Claude Code one-day training that includes practical labs on Git integration. You will learn to configure branch and automated PR workflows on your own repositories, with direct feedback from trainers.

Key takeaway: Claude Code automates the branch -> commit -> push -> PR chain in a single conversational instruction.


How to use checkpoints and the Esc+Esc shortcut?

Claude Code's checkpoint system creates an automatic Git snapshot before each modification. The Esc+Esc shortcut undoes the last action and restores the repository's previous state.

Example 7 - Restoration after an unwanted modification

Context: Claude Code modified a configuration file you did not want to touch.

# Claude Code just modified tailwind.config.ts by mistake
# Press Escape twice:
Esc + Esc

Expected result: Claude Code runs a git checkout on the files modified since the last checkpoint. The tailwind.config.ts file returns to its initial state in under 200 ms.

Example 8 - Manual checkpoint before a risky operation

Context: you are about to request a major refactoring and want an explicit restore point.

> Create a checkpoint before starting the refactoring
# Claude Code runs internally:
git stash push -m "claude-checkpoint-2026-02-20-14h32"
# Then after the refactoring, if needed:
git stash pop

Concretely, each checkpoint occupies less than 1 MB of Git storage. On a 50,000-line project, creating a checkpoint takes an average of 120 ms.

Check the Git integration troubleshooting guide if Esc+Esc restoration does not work as expected.

FeatureShortcut / CommandExecution time
Undo last actionEsc+Esc< 200 ms
Manual checkpoint"Create a checkpoint"~120 ms
Restore a checkpoint"Go back to previous checkpoint"< 300 ms
List checkpointsgit stash listinstant

Key takeaway: Esc+Esc is your safety net - use it without hesitation before and after any risky Git operation.


How to resolve merge conflicts with Claude Code?

Merge conflict resolution is one of Claude Code's most powerful use cases. Run a merge or rebase, then let Claude Code analyze and resolve the conflict markers.

Example 9 - Automatic resolution of a simple conflict

Context: you are merging a feature branch into main and Git signals a conflict in package.json.

> Resolve the merge conflicts in package.json

Expected result: Claude Code reads the <<<<<<<, =======, >>>>>>> markers, understands the semantic context, and produces:

{
  "dependencies": {
    "express": "^4.21.0",
    "zod": "^3.22.4",
    "prisma": "^5.18.0"
  }
}

Claude Code keeps both versions when they add different dependencies, and chooses the most recent version in case of concurrent update. In practice, 85% of conflicts on package.json and configuration files are resolved automatically.

Example 10 - Complex conflict in business code

Context: two developers modified the same calculateDiscount() function.

> Resolve the conflict in src/pricing/discount.ts
> keeping the logic from the feature branch
> but keeping the types from the main branch
// Result: intelligent merge
export function calculateDiscount(
  price: number,        // Type kept from main
  tier: CustomerTier    // Type kept from main
): DiscountResult {     // Type kept from main
  // Logic kept from feature
  const baseRate = TIER_RATES[tier] ?? 0;
  const volumeBonus = price > 1000 ? 0.05 : 0;
  return {
    discountedPrice: price * (1 - baseRate - volumeBonus),
    appliedRate: baseRate + volumeBonus,
  };
}

merge conflicts represent 12% of development time on projects with more than 5 contributors. To avoid recurring errors, check the common Git integration errors.

Key takeaway: Claude Code resolves conflicts by understanding the semantic context of the code, not just the position of modified lines.


How to navigate git log with Claude Code?

Claude Code transforms git log into a conversational analysis tool. Query the history in natural language to find commits, understand file evolution, or identify regressions.

Example 11 - Contextual search in history

Context: you are looking for when and why the authentication function was modified.

> What commits modified the auth.ts file
> in the last two weeks?

Expected result:

git log --oneline --since="2026-02-06" -- src/auth/auth.ts

# Claude Code displays a structured summary:
# 1. a3f21bc (Feb 12) fix(auth): fix refresh token - by Alice
# 2. 8e4d9f1 (Feb 10) feat(auth): add PKCE support - by Bob
# 3. c7b23a0 (Feb 7)  refactor(auth): extract middleware - by Alice

Claude Code adds a natural language summary: the file underwent 3 modifications in 2 weeks, including a critical bug fix and a feature addition.

Concretely, this analysis takes 1.2 seconds versus 5 to 10 minutes of manually reading the git log on a 2,000-commit project.

If you are getting started with Claude Code, the installation and first launch guide walks you through setting up your environment step by step.

Variant - Identifying a regression

> Find the commit that broke the tests in the /api folder
> between February 1 and February 15, 2026

Claude Code combines git log, git bisect, and test execution to isolate the problematic commit. This automated bisect operation reduces diagnostic time by 60% on projects with test coverage above 70%.

Key takeaway: the conversational git log transforms Git history into a knowledge base queryable in natural language.


What are the advanced examples of multi-step Git workflows?

Advanced workflows combine multiple Git operations in sequence. These examples show how to orchestrate complex scenarios with Claude Code.

Example 12 - Multi-file refactoring with complete PR

Context: you want to rename a React component used in 15 files, create a clean commit, and open a PR.

> Rename the UserCard component to ProfileCard everywhere in the project,
> create a branch refactor/rename-user-card,
> commit and open a PR with the list of modified files

Expected result:

# 1. Branch creation
git checkout -b refactor/rename-user-card

# 2. Renaming in all files (15 files modified)
# Claude Code uses contextual search and replace

# 3. Structured commit
git add -A
git commit -m "refactor(ui): rename UserCard to ProfileCard

- 15 files modified
- Imports updated automatically
- Tests adapted (no broken tests)"

# 4. Push and PR
git push -u origin refactor/rename-user-card
gh pr create --title "refactor(ui): rename UserCard -> ProfileCard" \
  --body "## Changes
- Rename UserCard to ProfileCard (15 files)
- No functional changes
- All tests pass (148/148)"

See how the custom commands guide lets you create reusable skills for this type of recurring refactoring.

To go further on these advanced workflows, the AI-Augmented Developer training from SFEIR Institute (2 days) covers in depth Git automation with AI agents, including labs on merge conflicts and multi-branch workflows. If you already master the basics, the AI-Augmented Developer - Advanced training (1 day) deepens CI/CD patterns and advanced orchestration.

WorkflowNumber of manual stepsWith Claude Code
Multi-file rename + PR8-12 steps1 instruction
Bisect + regression diagnosis15-20 steps1 instruction
Resolution of 3 conflicts + commit6-9 steps1 instruction
Branch + commit + PR + labels5-7 steps1 instruction

Key takeaway: multi-step workflows are the main productivity gain of Claude Code - a single sentence replaces dozens of Git commands.


How to customize Claude Code's Git behavior?

Configure the CLAUDE.md file at the root of your project to define your team's Git conventions. Claude Code will read these instructions at each session start.

# CLAUDE.md - Git Section
- Commit format: Conventional Commits (type(scope): description)
- Message language: English
- Default branch: develop
- PR template: always include ## Summary and ## Tests
- Never commit .env or credentials.json files
> Commit following the project conventions

Claude Code reads CLAUDE.md and automatically applies the rules. In practice, 90% of teams that configure this file see commit message uniformity from the first week.

Check the Git integration cheatsheet to find all commands and shortcuts at a glance. To configure your initial environment, the quickstart covers installation in under 5 minutes.

Key takeaway: the CLAUDE.md file is the central point for standardizing your team's Git conventions with Claude Code.


What pitfalls to avoid during Git integration with Claude Code?

Even with automation, certain practices require vigilance. Here are the most frequent errors and how to avoid them concretely.

  • Not reviewing the diff: Claude Code always displays the diff before committing. Read it systematically - 5% of automatic commits require a manual adjustment.
  • Forgetting sensitive files: add .env, credentials.json, and *.pem to your .gitignore before using Claude Code. The tool checks .gitignore but cannot guess your custom secret files.
  • Forcing a push without verification: Claude Code never does git push --force without your explicit approval. Keep this default behavior.
  • Ignoring checkpoints: the Esc+Esc shortcut only works if a checkpoint exists. On long sessions (more than 30 minutes), create manual checkpoints every 10 modifications.

23% of Git incidents in enterprises are caused by uncontrolled force pushes. Check the complete list of common Git integration errors to anticipate these situations.

Key takeaway: human verification of the diff remains indispensable - Claude Code accelerates the workflow but does not replace your judgment on committed content.


Recommended training

Claude Code Training

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

View program