Lesson 5 of 8 · 15 min · Checked on 10 October 2026
Essential Git with the agent at your side
By the end of this lesson you will be able to:
- Save return points in a folder with git init, git add and git commit
- See what changed and the history with git status, git diff and git log
- Go back on a file with git restore
- Ask the agent to run the Git commands and explain each one before you authorise it
Friday afternoon, the bakery page is just as it should be: opening hours, bread of the day, phone number. On Monday you ask the agent, “put in the winter opening hours.” It touches two files, the page ends up misaligned, and you no longer remember how it looked. The editor's Ctrl+Z does not help: the agent made the change, not you.
With Git, going back to Friday is one command.
The concept: a time machine for the folder
Git is a program that takes snapshots of a folder. Each snapshot is called a commit and carries a sentence from you saying what changed, for example “Winter opening hours on the home page”. A folder with these snapshots is called a repository.
Three ideas are enough to start:
- You decide when to take the snapshot. Git does not save anything on its own.
- The snapshots live in a hidden subfolder called
.git. Do not touch it by hand. - Any snapshot can be viewed or recovered later.
As you saw in the previous lesson, there are ways to go back when the agent makes a mess. Git is the safety net that works with any agent, even after you close the session, for everything you saved in a commit.
How it is done today
This is how it looks on 6 October 2026; your screen may differ. Look for the button with the same name. The commands come from the official Git book: Pro Git.
Once per computer. Check that you have Git:
git --version
If a version number appears, it is installed. If not, follow the “Installing Git” chapter of the book. Then tell Git who you are, because your name and email are written into every commit:
git config --global user.name "Your Name"
git config --global user.email "your-email@example.com"
The everyday commands. Create a folder called padaria (Portuguese for “bakery”) and go into it with cd padaria. With no files there is nothing to snapshot: first save an index.html there (with the editor or by asking the agent). Then, to save:
git init # turns on the time machine in this folder (only once)
git add . # gathers what changed for the next snapshot
git commit -m "First version" # takes the snapshot, with one sentence
To look, changing nothing:
git status # files changed, gathered for the commit, and new
git diff # line by line, what changed and is not gathered yet
git diff --staged # what you already gathered with git add
git log --oneline # the snapshots, newest first
git diff looks the way you already know: lines with - went out, lines with + came in. A new file, which Git does not follow yet, does not show in git diff: only in git status.
To go back to the last commit for one file, read this first:
Watch out
git restore asks for no confirmation: what you changed in that file since the last commit disappears. First check with git diff HEAD -- index.html what you will lose (and with git diff --staged -- index.html what you already gathered) and, if in doubt, copy the folder. The same goes, with more damage, for git reset --hard, git clean and git push --force. If one of these shows up in a permission request from the agent, stop and ask it to explain what gets lost.
git restore --source=HEAD index.html
Without --source=HEAD, git restore takes the version from what you gathered with git add, not from the last commit. And with --source=HEAD the gathered version stays in the staging area; to drop both, git restore --source=HEAD --staged --worktree -- index.html. Older guides use git checkout HEAD -- index.html, with the same effect on the file.
The agent at your side
You do not have to memorise this: Claude Code and Codex know Git and can do it for you. When it asks permission, you decide, so you need to understand what you are authorising.
Start Git in this folder and make the first commit with the message “First version of the bakery page”.
Before each command, explain in one sentence what it does and wait for my authorisation.
And at the end of any piece of work:
Explain to me, command by command, what you did in Git in this session and what was saved.
Tip
Make a commit at the end of every task that went well. Many small commits are better than one big one: if something goes wrong, you go back only a little.
Branches (parallel versions of the folder) wait for Level 2: if git status mentions “branch main” or “branch master”, ignore it for now.
A copy outside your computer: a GitHub account
Git keeps the snapshots on your computer. If the disk breaks, they go with it. GitHub is a service where you keep a copy of the repository on the Internet. You will need it in lesson 8 too, to put a website online.
- Open the GitHub sign-up page and follow the steps. You can also sign in with a Google or Apple account.
- Confirm your email. Without that, there are basic tasks GitHub will not let you do.
- Choose your username carefully: it will appear in the address of your site,
username.github.io. - If it offers you two-step verification, accept.
For now, send nothing there: that waits for lesson 8.
Tip
The email from git config is written into every commit and, in a public repository, anyone can see it. In GitHub's email settings there is the option “Keep my email addresses private”, which gives you a “noreply” address to use in git config instead of your own.
There are alternatives to GitHub, such as GitLab or Codeberg (European). In this course we use GitHub because GitHub Pages, in lesson 8, works with a free account.
Exercise
How I know it worked git log --oneline shows two lines, one per commit. After git restore, the deleted line is back and git status says there is nothing to save (“nothing to commit, working tree clean”).
If it didn't work
- “Author identity unknown” or “Please tell me who you are”: the
git configwith your name and email is missing. - “nothing to commit” on the first commit: the folder is empty or
git add .is missing. - “not a git repository”: you are in the wrong folder or you forgot
git init. See where you are withpwdand go into the right folder withcd. git logfilled the screen and will not leave: press theqkey.git statusshows files you do not recognise: ask the agent what they are before you make a commit.
Videos
Explains Git and GitHub using analogies, along with add and commit, .gitignore, branches, merge and pull requests.
Explains how Git works under the hood: commits, branches, HEAD, staging, checkout, reset and revert, rebase and reflog.
Test what you learned
Corrections to this lesson (2)
- : Second external review: before `git restore`, you look at `git diff HEAD -- index.html` and `git diff --staged -- index.html`; `git restore --source=HEAD` leaves the gathered version in the staging area, and the lesson gives the command to drop both.
- : After an external review: a file is created before the first commit; the lesson explains `git diff` and `git diff --staged` and that new files only show up in `git status`; question 3, about `git restore`, was corrected. Quiz options were reordered.