Pick up where you left off
Open your project in VS Code: File > Open Folder..., choose my-page. Then open a terminal
(Terminal > New Terminal) and check that everything is as you left it:
$ git statusOn branch main
nothing to commit, working tree clean“Working tree clean”: nothing has changed since your last commit. Good.
VS Code remembers the folders you opened. File > Open Recent gets you back to my-page
quickly next time.
Change your page
Add a line about yourself to index.html. The box below shows the whole file, with the line to
add highlighted. Use this text if you want your outputs to match this lesson exactly.
The safest way to change a file, here and in every lesson: click Copy on the box, click in
index.html in VS Code, press Ctrl+A (Cmd+A on a
Mac) to select everything, and paste over it with Ctrl+V
(Cmd+V). The file then matches the box exactly. If you type the line
instead, remember that VS Code adds the closing </p> as soon as you type <p>: type only the
sentence after it.
<!DOCTYPE html><html lang="en"><head> <meta charset="utf-8"> <title>My page</title></head><body> <h1>Hello, I'm learning Git!</h1> <p>This is my first web page.</p> <p>I like walking, photography and good coffee.</p></body></html>Ask Git what it sees:
$ git statusOn branch main
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: index.html
no changes added to commit (use "git add" and/or "git commit -a")Git knows index.html is modified: it is different from the last commit. The change is “not
staged”: it is in your working folder, but not yet in the staging area.
See exactly what changed: git diff
git status says which files changed. git diff shows how:
$ git diff
@@ -7,5 +7,6 @@
<body>
<h1>Hello, I'm learning Git!</h1>
<p>This is my first web page.</p>
+ <p>I like walking, photography and good coffee.</p>
</body>
</html>It looks technical, but you only need three things:
How to read git diff. The header names the file. Lines starting with + were added, lines
starting with - were removed, and lines starting with a space did not change: Git shows a few
of them so you can see where the change is.
- The first four lines say which file this is. Ignore the numbers on the
indexline. @@ -7,5 +7,6 @@says where in the file: around line 7.- Then the lines themselves:
+added,-removed, a space for lines that stayed the same.
In your terminal, added lines are green and removed lines are red.
VS Code shows the same thing in pictures. Click the Source Control icon in the bar on the left
(it looks like a branching line), then click index.html under “Changes”. VS Code shows the old and
new versions side by side. To get back to your files, click the top icon of the same bar (two
sheets of paper).
If something went wrong
git diff prints nothing. Either the change is not saved yet (a dot on the file’s tab in
VS Code means unsaved: press Ctrl+S, or Cmd+S on a
Mac), or you already ran git add: git diff only shows changes that are not staged. To see
staged changes, use git diff --staged.
I see a : or (END) at the bottom and cannot type. The output was longer than the screen.
Press q.
Save the change
The same two steps as before:
$ git add index.html$ git commit -m "Add a sentence about me"[main 358630b] Add a sentence about me
1 file changed, 1 insertion(+)Two commits now. Each one is a snapshot you can come back to.
Add a second file
Give your page some colour. Create a new file called style.css, the same way you created
index.html (New File... in the Explorer), and paste this text into it:
body { font-family: sans-serif; max-width: 40em; margin: 2em auto; padding: 0 1em; background: #fdfaf3; color: #222;} h1 { color: #2a6f97;}Then tell the page to use it: add the highlighted line to index.html (copy the box, select
everything in the file, paste).
<!DOCTYPE html><html lang="en"><head> <meta charset="utf-8"> <title>My page</title> <link rel="stylesheet" href="style.css"></head><body> <h1>Hello, I'm learning Git!</h1> <p>This is my first web page.</p> <p>I like walking, photography and good coffee.</p></body></html>If your page is open in the browser, reload it (F5, or Cmd+R on a Mac): the background turns cream, the font changes, the heading turns blue, and the text sits in a column in the middle of the window.
$ git statusOn branch main
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: index.html
Untracked files:
(use "git add <file>..." to include in what will be committed)
style.css
no changes added to commit (use "git add" and/or "git commit -a")One file is modified and one is new. Both belong in the same snapshot, because together they make one change: “add colours”. You could add them one by one, or all at once:
$ git add .$ git statusOn branch main
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
modified: index.html
new file: style.cssThe . means “this folder”, so git add . adds every change in the folder. It is quick, but
always run git status first, to be sure you are adding only what you mean to.
$ git commit -m "Add colours with a style sheet"[main f952430] Add colours with a style sheet
2 files changed, 13 insertions(+)
create mode 100644 style.cssLook back at your history
git log shows a lot for each commit. Add --oneline for one line each:
$ git log --onelinef952430 (HEAD -> main) Add colours with a style sheet
358630b Add a sentence about me
c50e3a0 Add my first web pageNewest first. Each line starts with the commit’s short hash, then its message. You can picture your history as a chain:
Your history is a chain of commits. Each commit is a full snapshot of the project, with a hash
and a message, and points back to the one before it. main is a label on the newest commit, and
HEAD marks the commit you are working on.
To look inside one commit, give git show its hash. Use a hash from your own list, not the one
printed here:
$ git show 358630bcommit 358630b7b7a64b3326a6d4c22d224a02ffaaf8a9
Author: Your Name <12345678+your-username@users.noreply.github.com>
Date: Thu Nov 5 10:05:00 2026 +0000
Add a sentence about me
@@ -7,5 +7,6 @@
<body>
<h1>Hello, I'm learning Git!</h1>
<p>This is my first web page.</p>
+ <p>I like walking, photography and good coffee.</p>
</body>
</html>git show prints the commit’s details and then its diff: exactly what that snapshot changed.
You do not have to type the whole hash. The first seven characters are enough, and even four usually work.
If something went wrong
fatal: ambiguous argument '358630b': unknown revision or path not in the working tree.
You typed the hash from this page. Your hashes are different: copy one from your own
git log --oneline.
The output stops, with : at the bottom. It is longer than the terminal panel. Press
Space to see the rest, and q to get your prompt back. To make the panel
taller, drag its top edge up.
Throw away a change you do not want: git restore
Everyone makes a mess sometimes. Make one on purpose: in index.html, change the heading and
delete the line about yourself, so the file looks like this.
<!DOCTYPE html><html lang="en"><head> <meta charset="utf-8"> <title>My page</title> <link rel="stylesheet" href="style.css"></head><body> <h1>Oops, I broke it</h1> <p>This is my first web page.</p></body></html>$ git statusOn branch main
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: index.html
no changes added to commit (use "git add" and/or "git commit -a")Look at the second hint: git restore throws away the changes you have not added with
git add. Nothing is staged here, so the file goes back to how it was in your last commit.
$ git restore index.html$ git statusOn branch main
nothing to commit, working tree cleanLook at index.html in VS Code: the heading and your sentence are back.
git restore throws those changes away for good. Git cannot bring them back, because they were
never in a commit. Use it only when you are sure.
Write messages your future self will thank you for
In a few months, your commit messages are all you will remember about each change. Good messages:
- say what the commit does, as an instruction: “Add a sentence about me”, “Fix the broken link”, “Change the heading colour”;
- are short, about 50 characters or fewer, so they fit on one line in
git log --oneline; - describe one change. If you need “and” to describe it, it may be two commits.
| Not so helpful | Helpful |
|---|---|
update |
Add a list of hobbies |
stuff |
Fix the spelling of "photography" |
changes to index and css and README |
Three commits, one for each change |
What you learned
git diffshows what changed and is not yet staged:+added,-removed.git add .stages every change in the folder. Checkgit statusfirst.git log --onelinelists your history, one commit per line;git show HASHshows one commit.git restore FILEthrows away changes to a file that you have not staged. They cannot be recovered.- A good message says what the commit does, briefly.
| Command | What it does |
|---|---|
git diff |
Shows changes that are not staged |
git diff --staged |
Shows changes that are staged |
git add . |
Stages every change in the current folder |
git log --oneline |
Lists commits, one per line |
git show HASH |
Shows one commit and its changes |
git restore FILE |
Discards changes to a file that are not staged |
Check yourself
git diff, what does a line starting with + mean?+ marks an added line and - a removed one. Lines with a space in front did not change.git add index.html, then git diff, and nothing was printed. Why?git diff --staged shows it.git log --oneline gives you the hash; git show HASH shows that commit’s changes.