Keep a way back
A Git checkpoint lets you compare a later experiment with a saved project. Your goal: save a small working program, make one change, then recover a selected file after inspecting it. Allow about 15 minutes, including practice.
Recognize the tools
Computer + terminal
Runs Git commands and the small test program.
Project folder
Holds your files and Git’s local history.
Plain text editor
Edits and saves main.py. Save before you test.
git --version and python --version.A checkpoint has two kinds of evidence
No electronics, Git account, remote service or development board is needed. If your Python command is python3 or py, use that command for the two program runs.
Know where the change is
A repository is a project with Git history. The working folder is what you edit. The staging area, also called the index, holds the contents selected for your next commit: a saved snapshot with a message.
git status
Shows new files and changes that are staged or still unstaged. Read the headings, not only the colors.
git diff / git diff --cached
The first compares working files with staging. The second reviews staging against the latest commit.
Adding is a snapshot
Check: only if you add the new contents before committing.
Create a safe practice project
Use a new folder called git-practice in your own working area. Do not run these setup commands inside a shared project or an existing repository.
1 · Initialize the folder
mkdir git-practice cd git-practice git init git config user.name "Course Learner" git config user.email "learner@example.invalid"
The two identity settings apply to this repository because these commands do not use --global. The example identity is for this throwaway exercise. Use your intended author identity in a real project.
2 · Make two plain text files
main.py
print("Ready")One small program. Make sure the filename is not main.py.txt.
.gitignore
.venv/ __pycache__/ .env private-notes.txt
One pattern on each line. Keep this file itself in Git.
Choose the files you will keep
Your source code helps you rebuild a project. Temporary dependencies and private information need different treatment. Inspect the file list before staging.
Read the four ignore patterns
Generated folders
.venv/ holds a Python environment. __pycache__/ holds automatically generated Python cache files. The ending slash identifies a folder pattern.
Private files
.env is often used for settings or credentials. private-notes.txt is an example personal note. Do not put real secrets into this exercise.
git status
Save the first checkpoint
Run the program first, then review exactly what will be saved. These commands all run inside git-practice.
1 · Observe a working result
python main.py
Ready. If you see a Python error, fix it and repeat this run before continuing.2 · Inspect and select the two files
git status git add -- main.py .gitignore git diff --cached git status
Read the staged patch: it should contain only the one-line program and the four ignore patterns. The -- separates options from the file names. This lesson names files explicitly so you can see what you selected.
3 · Record and find the checkpoint
git commit -m "Save ready greeting" git log --oneline -2 git status
Save ready greeting. The characters before it identify your saved commit; they will differ on each computer.Save ready greeting in the log. Status should report a clean working tree if there are no other files. The commit is local; it does not publish anything.Make one small change
In your editor, replace the message in main.py with Ready for the next step. Save the file, then run it again.
python main.py git diff -- main.py
git diff -- main.py
- print("Ready")
+ print("Ready for the next step")Stage and review the intended change
git add -- main.py git diff --cached -- main.py git status
Check that the new greeting is the staged version. If you edit the file again now, staging still holds the text from your last git add.
Need to unstage it?
git restore --staged -- main.py
After the first commit exists, this returns the staged entry to the latest commit. Your working edits stay in the file. Add again when ready.
Ready for the checkpoint?
git commit -m "Explain ready message" git log --oneline -2
Use this after the intended file is staged. The message says what changed.
git status is clean. A clean status alone does not prove the program worked.Read the saved versions
After the second checkpoint, the history has two saved project versions. You can read an earlier file without replacing your current one.
git log --oneline -2 git show HEAD:main.py
The newest log entry appears first. HEAD names the latest commit at your current position. HEAD:main.py means that saved file inside that snapshot.
Inspect the earlier greeting
Copy the commit ID beside Save ready greeting from your own log. In the command below, replace FIRST_ID with that ID; do not type FIRST_ID literally.
git show FIRST_ID:main.py
print("Ready"). Your working file still contains the longer message. Reading a snapshot has not changed that file.Recover one file with care
Now make a disposable scratch edit: change the message to Unwanted scratch, save it, and do not add it. We will replace only this working file with its latest committed version.
1 · Inspect both versions first
git status git diff -- main.py git show HEAD:main.py
HEAD means the latest commit at your current position. The show command displays its saved main.py without replacing your file.
2 · Restore the named file, then test
git restore --source=HEAD --worktree -- main.py python main.py git status
Ready for the next step again. Status is clean because the working file matches its saved version. The other files and two commits remain in place.For an older saved version, inspect it with git show COMMIT_ID:main.py first, replacing COMMIT_ID with an ID from your log. This exercise restores HEAD only.
Use the checkpoint in a real build
Git stores your chosen files. A useful hardware checkpoint also says what you tested, with which setup and what you observed.
Software observation
“main.py prints Ready for the next step after I run it.” That is the result tested in this practice.
Device observation
Record the actual board, firmware, connection and visible result when you test hardware. A successful commit does not prove a circuit works.
Your turn: a new small checkpoint
- Change the greeting to your own short message, save and run it.
- Use status and diff to inspect the intended change.
- Add only
main.py, review the staged diff and commit with a clear message. - Find the new message in the log and explain which version was saved.
Completion check
- Point to working files, staging and history in the diagram.
- Explain why an edit after adding needs another review and add.
- Find your checkpoints and show the saved file without changing it.
- Recover the disposable scratch edit in one named file.
Keep your reference
Keep the lesson beside your practice.
Download the PDF to keep the diagrams, commands, and checkpoints close at hand. Return to the first missing observation when a step does not match.
