Lessons · Git · both sides have moved
Both sides have moved
Diverged means you have commits the remote does not AND it has commits you do not. A plain push is refused, because moving the remote to your commit would drop theirs.
Hone is a place to practise programming. This is one of its lessons, written out in full and free to read without an account.
What it is for
It is the moment where the wrong command is expensive, and where two read-only commands show you exactly what each side would lose.
How to think about it
Look at both ranges before choosing. Two dots means 'in the right and not the left', so one range is what you would ask them to take and the other is what forcing would drop.
Worked example
git status -sbahead 1, behind 1. Both at once is the definition.
git log --oneline origin/main..HEADWhat you have that they do not.
git log --oneline HEAD..origin/mainAnd what they have that you do not. This is what a force would delete.
git push origin mainRefused, non-fast-forward. The refusal is the tool doing its job.
Your turn
List the commits the remote has that you do not.
git log --oneline
Try it in a real repository
The trap
Reading 'diverged' as an error. It is a description, and the three ways out -- merge, rebase, or decide one side is wrong -- are all ordinary.