THE GITHTML FIELD GUIDE

Resolve Git’s divergent-branches pull warning

When Git asks how to reconcile divergent branches, local and incoming histories both contain unique commits and no applicable policy resolves the choice. Fetch and inspect the divergence, then choose merge or rebase according to the project’s workflow. Fast-forward-only is a useful guardrail, but it cannot combine genuinely divergent histories.

Avoid turning a one-time error into global policy

The warning often suggests configuration commands, but choosing one globally affects unrelated repositories. First determine what happened in this project: perhaps a teammate pushed while you committed locally, or a previous rebase changed commit identities. The correct response depends on whether your local commits are private and how the team expects shared history to behave.

A merge retains the existing commits and creates an integration point. A rebase replays local commits on the incoming base, producing new identities. Neither is inherently the correct answer for every repository. A fast-forward-only policy deliberately refuses when both sides advanced, so its refusal is expected rather than a broken configuration.

Inspect current policy and unique commits

Use the actual upstream reference in place of origin/main. The configuration checks show whether local or global settings already influence pull behavior. Fetch first, then inspect the exclusive commits and their purpose. Avoid running several different pull variants while you are still learning the state.

  1. If the local commits are shared, prefer preserving their identities unless the team explicitly agrees to a rewrite.
  2. If they are unpublished and the project prefers rebasing, verify the selected base and preserve a recovery reference before replaying them.
shell
git status --short --branch
git config --show-origin --get pull.rebase
git config --show-origin --get pull.ff
git fetch origin
git log --left-right --oneline HEAD...origin/main

Make the chosen integration explicit

Use an operation-specific option or a repository-local policy when appropriate, then inspect the resulting history and files. If conflicts occur, finish or abort that operation before starting another strategy. A successful reconciliation still needs tests because both lines may have changed interacting behavior. Document the project’s chosen policy for future contributors instead of leaving everyone to infer it from their personal global configuration. If the task only requires reading remote updates, stop after fetch and inspection rather than integrating at all.

Preserve the full error text in a private troubleshooting note, including which branch was pulled. It helps distinguish a missing policy from an unrelated-history error, authentication failure, or conflict already in progress.

  1. If the project requires fast-forward-only pulls, do not permanently disable that safeguard to handle one divergence. Explain which local commits must be retained, then use the team’s explicit integration procedure. The refusal may be the expected prompt for a deliberate review of independently developed changes.
  2. After choosing a repository-local policy, inspect its configuration origin again in that repository. This distinguishes a saved preference from a one-command option. For a rebase, compare the resulting patches and behavior with the original local work; changed commit identifiers alone do not mean changes were lost.

Sources and further reading

AI-assisted writing with source-linked guidance and illustrative examples. Read our editorial approach or report a correction.

All fixing git problems guides →

Read as MarkdownAll guides

Resolve Git’s divergent-branches pull warning · gitHtml