◉CLAUDE LABJP
●2.1.301 — Adds the vim % motion, LaTeX math rendering in the VS Code panel, and a retry-watchdog limit for usage-limit waits (10/15)●2.1.299 — Conversations over 200K tokens left idle about 54 minutes get compacted; MCP allow rules now match only the server they name●SONNET 4.5 — Retires on the Claude API on 11/30, 45 days left. Migrate to Sonnet 5.5●WINDOWS — Reports say hooks break silently only on Japanese-locale Windows; check the character encoding first●FAST MODE — Opus 5.5 fast mode is out of research preview and no longer needs the beta header (10/15)●NEW — I Put a Ten-Line Promise File at the To…●2.1.301 — Adds the vim % motion, LaTeX math rendering in the VS Code panel, and a retry-watchdog limit for usage-limit waits (10/15)●2.1.299 — Conversations over 200K tokens left idle about 54 minutes get compacted; MCP allow rules now match only the server they name●SONNET 4.5 — Retires on the Claude API on 11/30, 45 days left. Migrate to Sonnet 5.5●WINDOWS — Reports say hooks break silently only on Japanese-locale Windows; check the character encoding first●FAST MODE — Opus 5.5 fast mode is out of research preview and no longer needs the beta header (10/15)●NEW — I Put a Ten-Line Promise File at the To…
Articles/Claude Code
⟐ Claude Code/2026-03-30Intermediate

How to Auto-Resolve Git Conflicts with Claude Code — Merge and Rebase Strategies

Learn how to resolve Git merge conflicts efficiently using Claude Code. This guide covers 3-way merge fundamentals, rebase conflict handling, complex resolution patterns, and automation techniques with practical command examples.

claude-code132git18conflict-resolutionmergerebaseteam-development

Why Use Claude Code for Git Conflict Resolution

In team development, Git merge conflicts are an inevitable part of the workflow. When multiple developers edit the same files simultaneously, running git merge or git rebase frequently results in conflicts that consume valuable development time.

Claude Code is an AI coding agent that operates directly from the terminal, capable of understanding code context at a deep level to resolve conflicts intelligently. Unlike traditional diff tools that compare text line by line, Claude Code analyzes what the code actually does and proposes contextually appropriate merge results.

How Merge Conflicts Occur

Before diving into resolution techniques, let's briefly review why conflicts happen in the first place.

Git uses a 3-way merge algorithm that compares changes from two branches against their common ancestor (base) to automatically merge them.

  • Base: The file content at the point where both branches diverged
  • Ours: Changes in the currently checked-out branch
  • Theirs: Changes in the branch being merged

When the same lines have been modified differently in both branches, Git cannot auto-merge and inserts conflict markers (<<<<<<<, =======, >>>>>>>) into the file, requesting manual resolution.

# Conflict marker example
<<<<<<< HEAD
const API_ENDPOINT = "https://api.example.com/v2";
=======
const API_ENDPOINT = "https://api.example.com/v3";
>>>>>>> feature/update-api

In this example, HEAD (the current branch) uses v2, while feature/update-api uses v3 — Git cannot determine which version to keep.

Basic Steps for Resolving Conflicts with Claude Code

Step 1: Assess the Conflict State

When a conflict occurs after a merge or rebase, inform Claude Code about the situation.

# After a merge with conflicts
git merge feature/update-api
# CONFLICT (content): Merge conflict in src/config.ts
 
# Ask Claude Code to resolve it
claude "A git merge conflict occurred. Please review and resolve all conflicts."

Claude Code will automatically perform the following steps:

  • Run git status to list conflicted files
  • Examine the diffs in each file
  • Analyze the conflict markers and propose an appropriate resolution
  • Edit the files to eliminate conflicts

Step 2: Review the Resolution

Always review the resolution Claude Code proposes. Crafting a more specific prompt leads to more accurate results.

# Prompt with explicit resolution policies
claude "Please resolve the git merge conflicts with the following policies:
- Prioritize changes from the feature branch
- Keep type definition changes from the main branch
- Integrate both sets of changes for test files"

Step 3: Commit and Finalize

After verifying that conflicts are resolved, stage and commit.

# Stage resolved files
git add .
 
# Create the merge commit
git commit -m "Merge feature/update-api: API v3 migration with test integration"

Handling Rebase Conflicts

Unlike merge, git rebase can trigger conflicts on a per-commit basis. When rebasing a branch with many commits, you may encounter conflicts on the same file multiple times.

# Start a rebase
git rebase main
 
# When a conflict occurs
# CONFLICT (content): Merge conflict in src/utils/parser.ts
# error: could not apply abc1234... Add parser utility
 
# Ask Claude Code for help
claude "A conflict occurred during rebase.
Current commit: abc1234 (Add parser utility)
Please resolve the conflict in src/utils/parser.ts
so I can run git rebase --continue"

With rebase, you need to run git rebase --continue after resolving each conflict. Communicating this flow to Claude Code streamlines the process.

# Automate sequential rebase conflict resolution
claude "Please resolve the rebase conflicts one by one.
After resolving each conflict, run git add and git rebase --continue.
If there's another conflict, continue resolving it.
Report the final result when everything is complete."

Practical Techniques: Complex Conflict Patterns

Pattern 1: Simultaneous Function Rename and Implementation Change

When one branch renames a function while another modifies its implementation, manual resolution becomes particularly challenging.

claude "Please perform a detailed conflict analysis:
- The main branch renamed processData() to transformData()
- The feature branch added validation logic to processData()
Reflect both changes by applying the new validation logic to transformData()"

Pattern 2: package.json and Lock File Conflicts

Dependency file conflicts are extremely common and prone to version inconsistencies when resolved manually.

# Resolve package.json conflict
claude "Please resolve the package.json conflict.
Policy: include all dependencies added by both branches.
If versions differ, adopt the newer one."
 
# Regenerate the lock file for safety
npm install
# or
yarn install

Pattern 3: Configuration File Structure Changes

Claude Code is also effective for conflicts in JSON/YAML configuration files like tsconfig.json or ESLint configs.

claude "Please resolve the tsconfig.json conflict:
- The main branch modified strict mode settings
- The feature branch added path aliases
Maintain valid JSON structure while reflecting both changes"

Automating Conflict Resolution with Claude Code Hooks

Claude Code's Hooks feature lets you automatically detect conflicts and streamline the resolution workflow.

Add the following configuration to .claude/settings.json:

{
  "hooks": {
    "PostToolUse": [
      {
        "matcher": "Bash",
        "hooks": [
          {
            "type": "command",
            "command": "if git status --porcelain | grep -q '^UU\\|^AA\\|^DD'; then echo 'CONFLICT_DETECTED: Conflicted files found'; fi"
          }
        ]
      }
    ]
  }
}

This configuration auto-detects conflict states after Claude Code executes Bash commands. For more advanced automation patterns, check out our Claude Code Hooks Workflow Automation Guide.

Best Practices for Conflict Prevention

Preventing conflicts is just as important as knowing how to resolve them.

Rebase frequently: The longer a branch stays diverged, the larger the conflicts become. Run git rebase main regularly to keep the diff small.

Keep branches granular: Implementing multiple features in a single branch widens the scope of potential conflicts. Split branches by feature and merge frequently.

Use CODEOWNERS files: Assigning file ownership reduces the likelihood of multiple developers editing the same files simultaneously.

Communicate: Simply sharing "I'm working on these files right now" within your team can dramatically reduce conflicts.

For a comprehensive look at team Git workflows, see our Claude Code Team Development Guide covering branch strategies and automated reviews.

Useful Git Commands for Conflict Diagnosis

Knowing how to gather accurate information before passing it to Claude Code leads to better results.

# List all conflicted files
git diff --name-only --diff-filter=U
 
# Show detailed 3-way diff
git diff --cc
 
# Inspect the 3-way merge state of a specific file
git show :1:src/config.ts  # base (common ancestor)
git show :2:src/config.ts  # ours (current branch)
git show :3:src/config.ts  # theirs (incoming branch)
 
# Abort a merge and start over
git merge --abort
 
# Abort a rebase and start over
git rebase --abort

You can feed these outputs to Claude Code for more precise conflict resolution.

# Pass 3-way diff information to Claude Code
claude "Please resolve the conflict based on this 3-way diff:
$(git diff --cc src/config.ts)"

Looking back

Using Claude Code for Git conflict resolution delivers more than just time savings — it provides context-aware merge results that understand the intent behind your code. The benefits are especially apparent when dealing with sequential rebase conflicts or complex cases where function renames and implementation changes overlap.

By clearly communicating your resolution policies, always reviewing the results, and combining resolution skills with prevention strategies, you can significantly streamline your team's Git workflow. To dive deeper into Git workflow automation, be sure to explore Automating Git Workflows with Claude Code as well.

Share

Thank You for Reading

Claude Lab is ad-free, supported entirely by members like you. We publish practical guides daily with implementation code, benchmarks, and production-ready patterns. If you've found it useful, we'd love to have you on board.

  • ✦Copy-paste ready implementation code
  • ✦New advanced guides published daily
  • ✦$5/mo or $10 for lifetime access
View Membership →

If you found this article helpful, a small tip ($1.50) would mean a lot to us. Your support helps keep this site ad-free and covers server and hosting costs.

Related Articles

⟐ Claude Code2026-08-28
A small script that catches invisible characters in plugin names before you install
Control characters and zero-width characters hiding in plugin or skill names are invisible in a terminal listing. I built six deliberately confusing names, compared what ls actually shows, and wrote a short check you can run before installing anything — plus an honest note on what that check misses.
⟐ Claude Code2026-08-26
I decide the prompt cache TTL by where I come back to, not how long I was away
Claude Code v2.1.242 added promptCacheTtl and subagentPromptCacheTtl. Whether the one-hour cache pays off depends on returning to the same directory and the same git state, not on how long the break was. Here is the order I check things in.
⟐ Claude Code2026-08-10
The Same rm -rf Was Recoverable in Ten Places and Unrecoverable in Five — Measuring Reversibility Before Auto Mode Becomes the Default
Auto mode became the default on Pro, Max and Team on August 14. It stops on operations judged irreversible, destructive, or outward-facing — but reversibility turned out to be a property of state, not of commands. Here is the probe and the measurements.