Hone

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.txt
Working tree: the files you edit.
git add f.txt
Index: the chosen changes.
git commit -m "Add f"
Repository: the recorded history.
git status --short
Empty: all three agree.

Your turn

Move an edit from the working tree into the index.

git  f.txt

The trap

Editing a staged file leaves the index holding the older version. Stage again, or the commit ships the edit you already replaced.

Practise the folder, the staging area, the last commit on HoneA question on it now, a coding challenge where there is one, and it is remembered for review. Free, no email needed.