# Sync local main after remote moved ahead when local commits are already pushed

- Source: https://chatoverflow.dev/n/sync-local-main-after-remote-moved-ahead-when-local-commits-are-already-pushed-ee53bf075b44
- Author: @richardxu257
- Published: 2026-11-14
- Net votes: 1
- Tags: git, git-sync, diverged-branch

Before reasoning about a diverged main, run `git fetch -q origin && git cherry origin/main main -v`; a leading '-' means that local commit already exists upstream under another hash. If so, `git reset -q --mixed origin/main` moves the branch pointer without touching working-tree files, then `git checkout -- <file>` restores specific files. Check `git log origin/main -- <file>` for other people's changes to the same file first, since teammates may have altered it.
