← Back to list

Your branch and ‘origin/main’ have diverged, and have X and Y different commits each, respectively

if you worked in a setup where several developers commit into one branch, you might see a teeny tiny bit annoying message when you, let’s…

Emad Dehnavi · 2026-02-18 13:27 · 10 claps · 0.9 min read paywalled
#git #rebase #git-tutorial #branching-strategy #git-pull
Open on Medium ↗
Wiki topics: 🔓 · Open Source

Your branch and ‘origin/main’ have diverged,

and have X and Y different commits each, respectively

if you worked in a setup where several developers commit into one branch, you might see a teeny tiny bit annoying message when you, let’s say wanna do a git pull :

Your branch and 'origin/YOUR_BRANCH' have diverged,
and have X and Y different commits each, respectively

That means:

  • You have X commits locally that remote doesn’t have
  • Remote has Y commits that you don’t have

Your branch and ‘origin/main’ have diverged

Your branch and ‘origin/main’ have diverged

You can do the following to make your branch sync with remote:

git fetch origin
git rebase origin/YOUR_BRANCH

That is effectively what git pull --rebase would do, but more explicit. This command will:

  • Move your branch to the latest remote commit
  • Re-apply your X commits one by one on top

But there also times in this situations, that you just want to move your branch pointer to remote. In that case you can do:

git fetch origin
git reset --hard origin/YOUR_BRANCH

This will do the followings:

  • Move your branch pointer to remote
  • Delete the X local commits (only locally), so your working directory are reset to the state of the target commit

메타데이터
post_id
bcd548f2a364
slug
your-branch-and-origin-main-have-diverged-and-have-x-and-y-different-commits-each-respectively-bcd548f2a364
url
https://medium.com/@emaddehnavi/your-branch-and-origin-main-have-diverged-and-have-x-and-y-different-commits-each-respectively-bcd548f2a364
canonical_url
https://medium.com/@emaddehnavi/your-branch-and-origin-main-have-diverged-and-have-x-and-y-different-commits-each-respectively-bcd548f2a364
author_url
https://medium.com/@emaddehnavi
status
ok
fetched_at
2026-07-13 10:58:23