🚀 Alguni Start learning

Unit 1: Save Points

Never lose your work again.

Unit 1 of 8 in Git and version control for kids. Its 5 lessons are Why Save?, Your First Commit, Asking git What Is Going On, The History Book and Save Point 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.

💾 Why Save?

The worst feeling

You spend an hour on a drawing. You try one more idea. It looks terrible — and now you cannot get the old one back.

Games solved this ages ago with save points. Git is a save point machine for your files.

What git actually is

Git is a program that watches a folder. Whenever you say so, it takes a photograph of every file and keeps it forever.

That photograph is called a commit. You can go back to any commit, any time.

Waking git up

Git does not watch every folder — that would be nosy. You switch it on for one folder with git init.

That makes a hidden folder called .git inside it. That hidden folder is the whole history. The folder is now a repository, or "repo".

Terminal

$ git init
Initialized empty Git repository in /home/you/project/.git/

Try it yourself

What is a commit?

  • A saved photograph of your files
  • A folder on your computer
  • A message you send to a friend
  • A kind of password

Where does git keep the history?

  • In the cloud
  • In a hidden .git folder inside your project
  • In your web browser
  • Nowhere — it forgets when you close the laptop

Answer them in the app

📸 Your First Commit

Two steps, not one

Saving takes two commands, and that is on purpose.

git add chooses which changes go in the photograph.
git commit takes the photograph and gives it a name.

Terminal

$ git add story.txt
$ git commit -m "Start the story"
[main (root-commit) 39a51dd] Start the story
 1 file changed, 1 insertion(+)
 create mode 100644 story.txt

Try it yourself

Which command takes the photograph?

  • git add
  • git commit
  • git init
  • git save

What makes a good commit message?

  • "stuff"
  • "Add the dragon to chapter 2"
  • "asdfgh"
  • Leave it blank, it does not matter

Answer them in the app

🔎 Asking git What Is Going On

git status is your friend

When you are lost, type git status. It always tells you three things: which branch you are on, what is about to be saved, and what is not.

Git even suggests the next command. Read what it says — it is trying to help.

Terminal

$ git status
On branch main

No commits yet

Untracked files:
  (use "git add <file>..." to include in what will be committed)
	story.txt

nothing added to commit but untracked files present (use "git add" to track)

After git add

Once you git add a file, git moves it into "Changes to be committed". It is *chosen* but not *saved* — the photograph has not been taken yet.

Terminal

$ git status
On branch main

No commits yet

Changes to be committed:
  (use "git rm --cached <file>..." to unstage)
	new file:   story.txt

Try it yourself

Git says a file is "untracked". What does that mean?

  • The file is broken
  • Git has never been told to look after this file
  • The file is saved and safe
  • Someone else is editing it

What one line does this print?

Terminal

git status --short

Answer them in the app

📖 The History Book

Reading your own history

git log lists every commit, newest first. Each one has a long code called a hash — its unique name — plus who made it, when, and the message.

git log --oneline squashes each commit onto one line. You will use that one far more.

Terminal

$ git log --oneline
caec904 (HEAD -> main) Add a dragon
39a51dd Start the story

HEAD -> main

In the log you will see (HEAD -> main) next to the newest commit.

main is the name of your line of work. HEAD is a finger pointing at where you are right now. Right now, both point at the same commit.

Terminal

$ git log --oneline
7edc026 (HEAD -> main) Say hello

Try it yourself

What is the 7-letter code at the start of each log line?

  • The commit hash — its unique name
  • A password
  • The number of files changed
  • The time it was saved

Which command shows the shortest, tidiest history?

  • git log
  • git log --oneline
  • git history
  • git show

Answer them in the app

🏆 Save Point Master

Try it yourself

You made a new folder for a project. What comes first?

  • git commit
  • git init
  • git add
  • git log

Answer it in the app