Skip to content

Git Divergent Branches: Fixing "Pulling without specifying how to reconcile divergent branches is discouraged"

This warning indicates Git needs guidance on how to handle branches that have diverged - meaning both your local branch and the remote branch have separate commits that aren't in the other.

Understanding the Problem

When your local repository and remote repository contain different commits that aren't based on each other, Git can't automatically determine the best way to combine them. This typically happens when:

  • You made local commits while others pushed changes to the remote branch
  • Someone force-pushed or rebased the remote branch
  • You're working with feature branches that diverged from the main branch

Git now requires explicit instructions on how to handle these scenarios to prevent unexpected merge commits or history rewriting.

1. Configure a Default Strategy (Best Long-term Solution)

Choose one of these configuration options based on your workflow:

bash
# Merge strategy (creates merge commits when needed)
git config --global pull.rebase false

# Rebase strategy (rewrites local commits on top of remote changes)
git config --global pull.rebase true

# Fast-forward only (aborts if not possible)
git config --global pull.ff only

TIP

Use --global to apply to all repositories, or omit it to configure only the current repository.

2. Command-Line Solutions for Immediate Use

For one-time solutions, use these flags with your pull command:

bash
git pull --no-rebase
bash
git pull --rebase
bash
git pull --ff-only

3. Manual Reconciliation Approaches

When you need more control over the process:

Option A: Rebase your changes

bash
git fetch origin
git rebase origin/main

Option B: Create a merge commit

bash
git fetch origin
git merge origin/main

Option C: Reset to match remote (WARNING: Discards local changes)

bash
git fetch origin
git reset --hard origin/main

Warning

The reset --hard command will permanently discard any uncommitted local changes and make your branch exactly match the remote. Use with caution.

Understanding the Strategies

Merge Strategy

  • How it works: Creates a merge commit that combines both histories
  • Best for: Team environments where you want to preserve exact history
  • Command: git pull --no-rebase or git config pull.rebase false

Rebase Strategy

  • How it works: Places your local commits on top of remote changes
  • Best for: Clean, linear history without merge commits
  • Command: git pull --rebase or git config pull.rebase true

Fast-Forward Only

  • How it works: Only updates if no merge is needed; aborts otherwise
  • Best for: Ensuring you never get unexpected merge commits
  • Command: git pull --ff-only or git config pull.ff only

Workflow Recommendations

For Solo Developers

bash
git config --global pull.rebase true

This creates a clean, linear history by rebasing your local changes on top of remote changes.

For Teams

bash
git config --global pull.rebase false

This preserves the complete history with merge commits, making it easier to track when integrations happened.

For Strict Quality Control

bash
git config --global pull.ff only

This ensures you must explicitly handle any divergence, preventing automatic merges that might introduce issues.

Troubleshooting Common Scenarios

When Fast-Forward Fails

If you get "Not possible to fast-forward, aborting":

bash
# Choose either merge or rebase approach:
git pull --no-ff        # Force a merge commit
git pull --rebase       # Rebase your changes

Using Git GUI Clients

Visual Studio (2019/2022):

  • Go to Git → Settings
  • Toggle "Rebase local branch when pulling"

GitHub Desktop:

  • Open repository in terminal (Ctrl + `)
  • Run configuration commands as above

SourceTree:

  • Actions → Open in Terminal
  • Run configuration commands

Best Practices

  1. Always pull before pushing to minimize divergence
  2. Communicate with your team about which strategy you're using
  3. Consider branch protection rules for important branches
  4. Use feature flags instead of long-lived divergent branches

Version-Specific Notes

  • Git 2.27+ shows the warning message
  • Git 2.29+ allows pull.ff configuration
  • Git 2.34+ makes the warning more specific about divergence
  • Git 2.35+ fixes several edge cases with fast-forward behavior

INFO

If you're using an older Git version, consider upgrading to access the most current behavior and fixes for divergent branch handling.

By choosing the appropriate strategy for your workflow and configuring Git accordingly, you can eliminate this warning and ensure your version control operations work predictably.