KevsRobots Learning Platform
By , Minute
Imagine you’re writing the code for a two-wheeled robot. It drives forward nicely. You add obstacle avoidance, and now it just spins on the spot. What did you change? Which version worked? If you’re lucky you made a copy first. If you’re like most of us, you didn’t.
People usually invent their own version control without realising it:
robot.py
robot_old.py
robot_v2.py
robot_v2_working.py
robot_final.py
robot_final_FIXED.py
This works until it doesn’t. You can’t tell what’s different between the files, why you made each change, or which one is actually the latest.
Git is a version control system. It keeps a complete history of your project in a hidden folder, and lets you:
You keep just one robot.py. Git remembers every version of it for you.
Git has some vocabulary that’s worth learning now, because you’ll see it everywhere.
Repository (or “repo”): a project folder that Git is tracking. It holds your files plus a hidden .git folder where Git stores the history.
Commit: a snapshot of your project at a moment in time. Each commit records which files changed, a message saying why, who made it, and when. Commits are the “save points” of your project.
Branch: a separate line of commits. The main line is usually called main. You can create a branch to work on something new, and merge it back when it’s ready.
Remote: a copy of your repository somewhere else, usually on a website such as GitHub. You push your commits to it and pull other people’s commits from it.
Here’s a picture of a small project’s history. Each circle is a commit, and time flows from left to right:
gitGraph
commit id: "Drive forward"
commit id: "Add turning"
branch obstacle-avoidance
commit id: "Add distance sensor"
commit id: "Avoid obstacles"
checkout main
commit id: "Fix motor speed"
merge obstacle-avoidance
The robot’s obstacle avoidance was built on its own branch while a motor fix went onto main, and then the two were joined back together. You’ll be doing exactly this by module 9.
This trips up almost everyone at first.
You can use Git for years without ever touching GitHub. But once you have commits, putting them on GitHub takes one command, and it’s how most open source projects (including the code for this website) are shared.
main.Have a look at a real Git project on GitHub, for example the MicroPython repository. Find the commits link near the top of the file list and click it. Each entry is a commit: notice the message, the author and the date. Click one to see the exact lines that changed.
Quick quiz 1 of 3
What is a commit?
Quick quiz 2 of 3
Which statement about Git and GitHub is true?
Quick quiz 3 of 3
Where does Git store the history of a repository?
.git folder. Delete it and the history is gone, but your files stay.
You can use the arrows ← → on your keyboard to navigate between lessons.
Comments