Hone

Lessons · Git · a commit is a save, a push is a backup

A commit is a save, a push is a backup

Git being distributed means every clone is complete, not that clones keep each other up to date. A commit lives on your machine until you push it.

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

The machine that dies is always the one with two days of unpushed commits on it, and no amount of committing helps.

How to think about it

Push your own branch constantly. Nobody has to look at a branch they were not asked to, and a pointer on the server costs the same as one locally.

Worked example

echo two days of work > w.txt
Work.
git add w.txt
Staged.
git commit -qm 'two days of work'
Committed. It feels safe.
git log --oneline
And it is here.
git log --oneline origin/main
It is not here. The remote has never heard of it.
git status -sb
ahead 1: the number that says how much only exists on this machine.
git push -q origin main
Now it is a backup.
git log --oneline origin/main
And the remote has it.

Your turn

See what the remote branch actually contains.

git log --oneline 

The trap

Reading 'distributed' as 'synchronised'. Every clone is complete; none of them updates itself.

Practise a commit is a save, a push is a backup on HoneA question on it now, a coding challenge where there is one, and it is remembered for review. Free, no email needed.