// tech tips · beginner
Git Basics for Beginners: Save Your Code History
Learn what Git is, how to install it, and the handful of commands you need to track changes, undo mistakes and back up your projects to GitHub.
Have you ever saved files called project_final.py, project_final2.py and project_REALLY_final.py? Git solves that problem properly. It keeps a full history of your project, lets you go back to any earlier version, and makes it easy to back up your code online. Almost every software team in the world uses it, so learning the basics early pays off.
What Git actually does
Git takes snapshots of your project folder whenever you tell it to. Each snapshot is called a commit, and it records exactly what changed, when, and a short message from you explaining why. You can look back through these commits, compare them, and return to any of them.
Git runs on your own computer. GitHub is a separate website that stores copies of Git projects online, so you can back them up and share them. You can use Git without GitHub, but they work well together.
Step 1: Install Git
- Windows: download it from git-scm.com and run the installer. The default options are fine.
- Mac: open Terminal and type
git --version. If Git isn’t installed, macOS will offer to install it for you. - Linux: run
sudo apt install giton Ubuntu or Debian.
Check it worked:
git --version
Step 2: Tell Git who you are
Every commit records who made it. Set your name and email once:
git config --global user.name "Your Name"
git config --global user.email "you@example.com"
If you’ll use GitHub, use the same email as your GitHub account.
Step 3: Start tracking a project
Open a terminal in your project folder (the built-in terminal in VS Code is perfect) and run:
git init
This creates a hidden .git folder where Git stores the whole history. Your files aren’t changed at all.
Step 4: The everyday cycle
Working with Git comes down to three commands you’ll repeat constantly.
1. See what’s changed:
git status
New and changed files are listed in red. They’re not in a snapshot yet.
2. Choose what goes into the next snapshot:
git add todo.py
git add . # or add everything that changed
This is called staging. Staged files show in green in git status.
3. Take the snapshot:
git commit -m "Add a remove option to the to-do app"
That’s it, your work is saved in the history. The repeating rhythm is: edit → git status → git add → git commit.
Writing good commit messages
Your future self will read these, so make them useful:
| Weak | Better |
|---|---|
update |
Fix crash when task number is 0 |
stuff |
Add high score saving to quiz |
asdfgh |
Rename variables to be clearer |
A good message finishes the sentence “This commit will…”. Commit small, focused changes often, rather than one giant commit at the end of the day.
Looking at your history
git log --oneline
a3f9c21 Add a remove option to the to-do app
7b2e004 Save tasks to JSON
1c8d5aa First working version
Each line is one commit, with a short ID at the start. To see exactly what changed in files you haven’t committed yet:
git diff
Undoing mistakes
Git’s real superpower is that mistakes stop being scary.
Throw away changes to a file since the last commit:
git restore todo.py
Unstage a file you added by mistake (your changes are kept):
git restore --staged todo.py
Undo a whole commit safely, by creating a new commit that reverses it:
git revert a3f9c21
Careful:
git restore todo.pypermanently discards uncommitted edits to that file. Rungit difffirst if you’re not sure.
Ignoring files you don’t want to track
Some files shouldn’t go into Git: saved data, passwords, and folders that tools create automatically. Make a file called .gitignore in your project folder and list them:
__pycache__/
.venv/
tasks.json
.env
Git will now act as if those files don’t exist. Never commit passwords or API keys. Once they’re in the history, they’re hard to remove completely.
Backing up to GitHub
- Create a free account at github.com and click New repository. Give it a name and leave the other options empty.
- GitHub shows you some commands. They look like this (with your username and repository name):
git remote add origin https://github.com/your-username/todo-app.git
git branch -M main
git push -u origin main
The first time, Git will ask you to sign in to GitHub. After that, whenever you’ve made new commits, upload them with:
git push
Your code is now backed up, and you can share the link with anyone. A GitHub profile with a few small projects is also a great thing to show to teachers or employers.
A quick-reference card
| Command | What it does |
|---|---|
git init |
start tracking the current folder |
git status |
show what’s changed and what’s staged |
git add <file> / git add . |
stage changes for the next commit |
git commit -m "message" |
save a snapshot |
git log --oneline |
list previous commits |
git diff |
show unstaged changes line by line |
git restore <file> |
discard uncommitted changes to a file |
git push |
upload commits to GitHub |
git pull |
download new commits from GitHub |
Key points
- Git saves snapshots of your project called commits.
- The daily cycle is edit →
git add→git commit. - Write short, specific commit messages and commit often.
- Use
.gitignorefor data, virtual environments and secrets. - GitHub stores a backup online;
git pushsends your commits there.
Try it now: run git init in the folder of your to-do app and make your first commit.