World map

 

BM: Baca dalam Bahasa Melayu

World 1: Save Points

The Box

You will learn: how to save only the files that are ready.

The problem

Three files wobble on your desk: index.html, style.css and about.html. Only index.html has a green tick.

You changed 3 files. Only 1 is ready. How do you save just that one?

Watch

The ticked file, index.html, glows and slides into the amber box. style.css and about.html stay behind.

Git has a box. It is called the staging area. Ready changes go in the box.

Watch

The command git add index.html types itself. Then index.html slides into the box.

git add index.html puts one file in the box.

Try it

Tap a file, then tap a box. Or drag it.

  • Drop here

Drag only the ready file into the box.

Try it

Working folder
Staging area
  • Empty
Repository
  • 1 save point
  • Add README

Now type the command yourself.

Watch

A camera flash. A snapshot of the box flies onto the timeline as a new commit. The box is now empty.

A commit takes a photo of the box. Only what is inside gets saved.

Predict

You run git commit now. Which files are saved?

Pick one answer.

Check

git status after adding index.html. Terminal output: $ git add index.html $ git status On branch main Changes to be committed: (use "git restore --staged <file>..." to unstage) new file: index.html Untracked files: (use "git add <file>..." to include in what will be committed) about.html style.css

In git status, green means “in the box”. Red means “not yet”.

You did it!

You can now save only what is ready.

Go deeper (optional)

git add -p saves only part of a file. git restore --staged takes a file out of the box.

Add index.html, then take it out of the box again. Terminal output: $ git add index.html $ git status -s A index.html ?? about.html ?? style.css $ git restore --staged index.html $ git status -s ?? about.html ?? index.html ?? style.css