Git: Beginner to Advanced
What Git tracks
Understand how one file can have different working, staged, and committed versions.
Lesson 1 of 12
Reading: about 2 min
Lesson + practice: about 8 min
Difficulty: Beginner
On this page4 sections
A Git repository keeps a history of snapshots. Before a change enters that history, you edit a file in the working tree and choose a version for the index, also called the staging area. Git works locally; a hosting service helps you share the repository.
Three places a file can live
The working tree is what you edit. The index prepares the next snapshot. History holds snapshots already committed. Follow notes.md through all three places in the walkthrough.
The diagram follows notes.md through the working tree, index, and commit history.
Editing after staging
At step 3, the working file says “Hello, Git!” while the index still holds “Hello”. git add copies a version into the index; it does not keep the index linked to later edits.
git status --short| Status | File |
|---|---|
| AM | notes.md |
Making the first commit
At step 4, git commit saves the index version: “Hello”. The newer working edit remains outside commit A.
git commit -m "Add notes"
git log --oneline -1| Example ID | Message |
|---|---|
| a1b2c3d | Add notes |
Check your understanding
After step 4, which text did commit A save: “Hello” or “Hello, Git!”?
Reveal answer
Commit A saved “Hello”, the version in the index. “Hello, Git!” remains in the working tree. Stage and commit again to include it.
Your progress
Reveal the check answer or reach the end to complete this lesson.