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.txtWork.
git add w.txtStaged.
git commit -qm 'two days of work'Committed. It feels safe.
git log --onelineAnd it is here.
git log --oneline origin/mainIt is not here. The remote has never heard of it.
git status -sbahead 1: the number that says how much only exists on this machine.
git push -q origin mainNow it is a backup.
git log --oneline origin/mainAnd the remote has it.
Your turn
See what the remote branch actually contains.
git log --oneline
Try it in a real repository
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.