Hone

Lessons · Git · what git can see right now

What Git thinks right now

git status shows which files are untracked, modified or staged. Run it before every command you are not sure about.

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 cheapest way to know what the next command will do: whether a commit will include your edit, whether a switch will refuse, whether a new file is even known to Git.

How to think about it

Read --short as two columns: the first is the index (staged), the second the working tree. ?? is untracked, A is added, M is modified; where the M sits tells you whether it is staged.

Worked example

echo hello > a.txt
A new file Git has never seen.
git status --short
?? a.txt: untracked.
git add a.txt && git status --short
A a.txt: staged, ready to commit.
git commit -q -m "Add a" && echo more >> a.txt && git status --short
M a.txt: modified in the working tree, not staged.

Your turn

See the state of every file, one line each.

git  --short

The trap

MM a.txt means you staged a change and then edited the file again. The commit will contain the older, staged version, not your latest edit.

Practise what git can see right now on HoneA question on it now, a coding challenge where there is one, and it is remembered for review. Free, no email needed.