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.txtA new file Git has never seen.
git status --short?? a.txt: untracked.
git add a.txt && git status --shortA a.txt: staged, ready to commit.
git commit -q -m "Add a" && echo more >> a.txt && git status --shortM a.txt: modified in the working tree, not staged.
Your turn
See the state of every file, one line each.
git --short
Try it in a real repository
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.