Hone

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 -sb
ahead 1, behind 1. Both at once is the definition.
git log --oneline origin/main..HEAD
What you have that they do not.
git log --oneline HEAD..origin/main
And what they have that you do not. This is what a force would delete.
git push origin main
Refused, 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 

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.

Practise both sides have moved on HoneA question on it now, a coding challenge where there is one, and it is remembered for review. Free, no email needed.