What Git does for a project
Git is a tool that records every version of the files in a project. It shows what changed, when it changed and who changed it. It matters because you can go back to any earlier version, so a mistake never costs you your work.
Think of a report you edit for weeks, with files called final, final2 and really-final. Git replaces that mess with one folder and a clear history.
By the end of this lesson
Note
I can record my changes as commits and read the history.
Key words
| Word | What it means |
|---|---|
| Repository | a project folder whose history Git keeps |
| Commit | a saved snapshot of the project, with a message |
| Staging area | the waiting place for changes before a commit |
| Log | the list of commits, newest first |
| Hash | the long code that names one commit |
The cells students fill in are left blank in this preview.
A commit saves a snapshot of your project
A repository is a project folder whose history Git keeps. Each time you save a step of your work, Git stores a commit. A commit is a snapshot of the project, with a message that says why you made it.
Each commit points back to the one before it. The commits form a chain, and that chain is the history.
Git writes your name on every commit
You tell Git who you are once. It keeps the answer for the whole lab.
First make a repository called menu. The -b main part names its first branch main. Then set your name and address.
Make a repository called menu
git init -b main menuShown here, not run. Create a free account to press Run and type it into your own lab’s terminal.
Tell Git your name
git config --global user.name "Student"Shown here, not run. Create a free account to press Run and type it into your own lab’s terminal.
Tell Git your address
git config --global user.email "[email protected]"Shown here, not run. Create a free account to press Run and type it into your own lab’s terminal.
Add chooses what goes into the next commit
Git does not save every change on its own. You choose. The command git add copies a file's current state into the staging area. The command git commit then saves everything waiting there.
The command git status --short shows where each file stands. It puts two letters before each file name.
Worked example: what the two letters say
| Letters | What they mean | When you see them |
|---|---|---|
| `??` | Git has never seen this file | After you make a new file |
| `A ` (A, then a space) | A new file is staged | After git add on a new file |
| ` M` (a space, then M) | A known file changed, and it is not staged | After you edit a file |
| `M ` (M, then a space) | A known file changed, and it is staged | After git add on an edited file |
The cells students fill in are left blank in this preview.
Make a file with two prices
printf 'Latte 3.20\nTea 2.10\n' > menu/prices.txtShown here, not run. Create a free account to press Run and type it into your own lab’s terminal.
Ask where the file stands
git -C menu status --shortShown here, not run. Create a free account to press Run and type it into your own lab’s terminal.
Stage the file
git -C menu add prices.txtShown here, not run. Create a free account to press Run and type it into your own lab’s terminal.
Ask again
git -C menu status --shortShown here, not run. Create a free account to press Run and type it into your own lab’s terminal.
Save the first commit
git -C menu commit -m "Add the first prices"Shown here, not run. Create a free account to press Run and type it into your own lab’s terminal.
A common mistake
Warning
Many people think git add saves their work into the history. It does not. It only stages the change. Nothing is in the history until you run git commit, so a staged file that is never committed can still be lost.
The log lists the commits, newest first
Edit the file, look at what changed, and commit again. The option -a on git commit stages every file Git already knows, so you skip git add. It does not stage new files.
Then read the history with git log. The option --format chooses what each line shows: %an is the author and %s is the message.
Add a third price
printf 'Cake 3.50\n' >> menu/prices.txtShown here, not run. Create a free account to press Run and type it into your own lab’s terminal.
See how much changed
git -C menu --no-pager diff --statShown here, not run. Create a free account to press Run and type it into your own lab’s terminal.
Commit every known file
git -C menu commit -am "Add cake"Shown here, not run. Create a free account to press Run and type it into your own lab’s terminal.
Read the log, one line each
git -C menu --no-pager log --format="%an|%s"Shown here, not run. Create a free account to press Run and type it into your own lab’s terminal.
An example of the full log
commit 451fb8e70cc390c845b7fb933284a7b883acf945
Author: Student <[email protected]>
Date: Sun Oct 25 23:53:39 2026 +0000
Add cake
Four facts sit in every log entry
The plain git log shows each commit in four parts. The first line holds the hash, a 40-character code that names the commit for ever. The second line names the author. The third gives the date.
The message comes last, indented by four spaces. The example above is only an example: your hash and date differ. When Git prints to a terminal, the first line can also end with names such as (HEAD -> main).