Lessons · Git · the folder, the staging area, the last commit
Working tree, index, repository
You edit in the working tree, choose with add into the index (the staging area), and record with commit into the repository. Every Git command moves changes between these three.
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 confusing Git moment is not knowing which area a change is in. Once you can say 'that edit is in the working tree but not the index', the right command is obvious.
How to think about it
For any change ask: which of the three has it? git status answers. Then pick the command that moves it one step: add (tree to index), commit (index to repository), restore (back again).
Worked example
echo x > f.txtWorking tree: the files you edit.
git add f.txtIndex: the chosen changes.
git commit -m "Add f"Repository: the recorded history.
git status --shortEmpty: all three agree.
Your turn
Move an edit from the working tree into the index.
git f.txt
Try it in a real repository
The trap
Editing a staged file leaves the index holding the older version. Stage again, or the commit ships the edit you already replaced.