Hone

Lessons · Git · what to do before you touch anything

Look before you touch

Three read-only commands answer where you are, what the history looks like, and what is uncommitted. None of them changes anything, so none of them can make it worse.

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

Almost every story that ends with lost work has a command near the start that was typed before anybody knew what state the repository was in.

How to think about it

status, log, branch. Then decide. The temptation is to reach for reset or a fresh clone, and both destroy the evidence you have not read yet.

Worked example

git status --short
One modified file, unstaged. So there IS uncommitted work here.
git log --oneline
One commit. If you were expecting two, that is the thing to explain.
git branch --show-current
main. An empty answer here would mean a detached HEAD.
git reflog
Where HEAD has been, newest first -- and the commit that is missing from the log is in it.

Your turn

Show every position HEAD has been in.

git 

The trap

Re-cloning. It gets you what the server has, and everything unpushed -- your commits, your stash, your reflog -- is not on the server.

Practise what to do before you touch anything on HoneA question on it now, a coding challenge where there is one, and it is remembered for review. Free, no email needed.