Unit 2: The Three Places
Working, staged, saved.
Unit 2 of 8 in Git and version control for kids. Its 4 lessons are Working, Staged, Saved, One Idea, One Commit, Things git Should Ignore and Staging Master — below is everything each one explains, and a question or two from it to try.
Every terminal session on this page was replayed before it shipped, on a git whose every message is tested against the real one.
This unit is free for ever, because the first two units of every track are. Try it in the app.
📦 Working, Staged, Saved
Three places a change can be
Think of packing a parcel.
Working folder — your desk. Everything you are messing with.
Staging area — the open box. The things you have decided to send.
History — the sealed, posted parcels. Commits.
git add puts something in the box. git commit seals it.
Status draws the line
git status puts staged things under Changes to be committed and unstaged things under Changes not staged for commit.
Here hero.txt is in the box, and villain.txt is still on the desk.
Terminal
$ git status On branch main Changes to be committed: (use "git restore --staged <file>..." to unstage) modified: hero.txt Changes not staged for commit: (use "git add <file>..." to update what will be committed) (use "git restore <file>..." to discard changes in working directory) modified: villain.txt
Try it yourself
You edited a file but have not run git add. Where is the change?
- In the working folder only
- In the staging area
- In a commit
- Gone forever
In that status, which file would end up in the next commit?
- Both of them
- hero.txt only
- villain.txt only
- Neither
Answer them in the app
🎯 One Idea, One Commit
Why bother with the box?
Because you often change two unrelated things before you remember to save.
Staging lets you post them as two separate parcels: one commit that fixes the spelling, one that adds the dragon. Later, you can undo the dragon without losing the spelling fix.
Two files, two commits
Add one file, commit it, then add the other and commit that. Two neat save points instead of one muddle.
Terminal
$ git add book.txt $ git commit -m "Fix the spelling of Chapter" [main 6ede186] Fix the spelling of Chapter 1 file changed, 1 insertion(+), 1 deletion(-) $ git add notes.txt $ git commit -m "Add dragon notes" [main fa4d53d] Add dragon notes 1 file changed, 1 insertion(+), 1 deletion(-) $ git log --oneline fa4d53d (HEAD -> main) Add dragon notes 6ede186 Fix the spelling of Chapter 51f75b2 Start the book
Try it yourself
You fixed a typo AND added a new chapter. What is tidiest?
- One commit called "stuff"
- Two commits: one for the typo, one for the chapter
- No commits, just remember it
- Delete the file and start again
Answer it in the app
🙈 Things git Should Ignore
Not everything belongs in history
Some files should never be saved: giant videos, secret passwords, junk your computer made by itself.
Make a file called .gitignore and list them. Git will stop mentioning them, and git add . will skip them.
Before and after
Here secret.txt is untracked and in the way. One line in .gitignore makes it invisible to git — but the file itself is still on the disk, exactly where you left it.
Terminal
$ git status --short ?? notes.txt ?? secret.txt $ echo "secret.txt" > .gitignore $ git status --short ?? .gitignore ?? notes.txt
Ignoring a whole family of files
A * means "anything". *.log ignores every file ending in .log. A name ending in / ignores a whole folder.
.gitignore itself should be committed — everyone working on the project wants the same list.
Terminal
$ echo "*.log" > .gitignore $ git status --short ?? .gitignore ?? game.txt
Try it yourself
What does .gitignore do to a file it lists?
- Deletes it
- Hides it from git, but leaves it on your computer
- Locks it so you cannot edit it
- Uploads it somewhere safe
Which line ignores every file ending in .mp4?
- mp4
- *.mp4
- ignore mp4
- .mp4/
Answer them in the app
🏆 Staging Master
Try it yourself
Which order is right?
- working folder → staging area → history
- history → staging area → working folder
- staging area → working folder → history
- They all happen at once
Answer it in the app