By Kevin McAleer, 5 Minutes
Page last updated November 24, 2026

By the end of this lesson you will be able to explain what Git is for, install it on your Pi, and set up your name and email so it can label your work.
Have you ever edited a script, broken it, and wished you could go back to yesterdayβs version? Git is a tool that remembers every saved version of your files, who changed them and why. It is the same tool used by millions of programmers, and it is how most Docker projects, robot code and websites (including this one) are shared.
You do not need an account anywhere to use Git. It works entirely on your Pi, and later you can put a copy on a site such as GitHub if you want to share it. For our Docker-ready Pi, it means that the scripts and settings in ~/homelab can be tracked and rolled back, so you can experiment without fear.
flowchart LR
W["Working folder: the files you edit"] -->|"git add"| S["Staging area: what goes in the next snapshot"]
S -->|"git commit"| R["Repository: the saved history"]
R -->|"git checkout / restore"| W
Git has three places, shown above. You edit files in the working folder, choose which changes to include with git add, and save a labelled snapshot (a commit) with git commit. The next lesson practises these.
Check whether you already have it:
$ git --version
git version 2.x.x
If it says command not found, install it with the package manager from lesson 6:
$ sudo apt update
$ sudo apt install git
Run git --version again to confirm. The exact number does not matter.
Every commit is labelled with a name and an email. Set them once for your user:
$ git config --global user.name "Your Name"
$ git config --global user.email "[email protected]"
$ git config --global init.defaultBranch main
The third line makes new repositories start on a branch called main, which avoids a hint message you would otherwise see. Check what you saved:
$ git config --global --list
user.name=Your Name
user.email=[email protected]
init.defaultBranch=main
This is stored in a file called ~/.gitconfig. You can read it with cat ~/.gitconfig.
Careful: your commit email can become public if you push your work to a website. If that worries you, use an address your Git hosting site gives you for this, such as GitHubβs
noreplyaddress, or any made-up address, since Git does not check it.
Teachers: do not ask pupils to use personal email addresses for Git. Git does not verify the address, so a class code or a made-up address like
[email protected]works fine for local use. Only create accounts on sites such as GitHub with your schoolβs agreement, and check their minimum age rules before anyone signs up. Everything in this course works with no account at all.
Pi progress: Git is installed and knows who you are. Next we put ~/homelab/scripts under version control.
git --version, and if needed install Git with apt.git config --global user.name to read the name back.~/.gitconfig with cat and find the three lines you set.git help commit (it uses the manual page viewer) and find what -m does.git: command not found.sudo apt install git.Why: Git is not part of every Raspberry Pi OS image.
Please tell me who you are.git config --global commands for name and email.Why: Git refuses to make a commit with no author information.
git config --global command again with the correct value.Quick quiz 1 of 4
What does Git do?
Quick quiz 2 of 4
What is a commit?
Quick quiz 3 of 4
Which command installs Git on Raspberry Pi OS?
apt installs it.Quick quiz 4 of 4
Do you need an online account to use Git on your Pi?
Comments