02 — Git and GitHub
Git vs. GitHub
Git is a version-control system that tracks changes to files on your computer.
GitHub is an online service that hosts Git repositories and makes it easier to share code, collaborate, and distribute projects.
In this course, GitHub may also be used through GitHub Classroom to distribute starter code for assignments.
Why use Git?
Git helps you:
- keep a history of your code;
- recover earlier versions after a mistake;
- work on the same project from multiple computers;
- collaborate without constantly emailing files;
- back up committed work by pushing it to GitHub.
Commit regularly and push important work to GitHub. A file that only exists on your laptop is not a backup.
1. Install Git
Raspberry Pi OS
Git is usually preinstalled on Raspberry Pi OS. Check first:
git --versionIf it is not installed:
sudo apt update
sudo apt install git -yUbuntu/Linux
sudo apt update
sudo apt install git -ymacOS
Try:
git --versionIf Git is not installed, macOS may offer to install the Xcode Command Line Tools.
Git downloads and documentation:
Verify the installation:
git --version2. Configure your identity
Git records an author name and email with each commit.
Set them once:
git config --global user.name "Your Name"
git config --global user.email "your_email@example.com"Check the configuration:
git config --global --listUsing the email associated with your GitHub account makes it easier for GitHub to associate commits with your profile.
3. Clone a repository
git clone downloads an entire repository and its version history.
For example:
git clone https://github.com/ariarobotics/cv.gitThen enter the repository:
cd cvThe course materials are maintained on the repository’s main branch, which is the default branch. A normal clone therefore downloads the correct version:
git clone https://github.com/ariarobotics/cv.gitFor assignments distributed through GitHub Classroom, use the repository link provided for that assignment.
4. The basic Git workflow
The commands you will use most often are:
git status
git pull
git add -A
git commit -m "Describe what changed"
git pushA typical workflow is:
Step 1 — Check the repository
git statusThis shows:
- modified files;
- new/untracked files;
- staged files;
- your current branch.
Step 2 — Pull recent changes
Before beginning work on a shared repository:
git pullStep 3 — Edit your files
Use VS Code, Thonny, or another appropriate editor.
Step 4 — Review what changed
git status
git diffgit diff is especially useful before committing because it shows the exact line-by-line changes.
Step 5 — Stage changes
Stage everything:
git add -AOr stage a specific file:
git add path/to/file.pyStep 6 — Commit
git commit -m "Implement image filtering"A commit saves a snapshot in the local Git repository.
Step 7 — Push
git pushThis sends your local commits to GitHub.
git commit and git push are different operations. A commit saves the change locally; a push sends committed changes to GitHub.
5. Essential commands
| Command | Purpose |
|---|---|
git clone URL |
Download a repository |
git status |
Show repository status |
git pull |
Download and integrate remote changes |
git add FILE |
Stage a file |
git add -A |
Stage all changes |
git diff |
Inspect unstaged changes |
git diff --staged |
Inspect staged changes |
git commit -m "message" |
Create a commit |
git push |
Upload commits |
git log --oneline |
Show commit history |
6. Branches
A branch is an independent line of development. Working on a branch lets you make changes without affecting the main branch until you are ready to merge them.
Create and switch to a new branch:
git checkout -b feature-nameList branches:
git branchSwitch back to main:
git checkout mainMerge a branch into main:
git checkout main
git merge feature-namePush a new branch to GitHub:
git push -u origin feature-nameIndividual assignments can usually be done directly on main. For team projects such as the capstone, use a separate branch per feature and open a pull request on GitHub before merging into main.
7. GitHub authentication
GitHub no longer accepts your account password for Git operations over HTTPS. Use one of the following instead.
Personal access token (HTTPS):
- On GitHub: Settings → Developer settings → Personal access tokens → Generate new token
- When Git prompts for a password while pushing or pulling, paste the token instead
SSH key (recommended if you push often):
ssh-keygen -t ed25519 -C "your_email@example.com"Add the contents of ~/.ssh/id_ed25519.pub to GitHub under Settings → SSH and GPG keys, then test the connection:
ssh -T git@github.comClone using the SSH URL (git@github.com:owner/repo.git) instead of the HTTPS URL to use the key automatically.
8. GitHub Classroom
Assignments distributed through GitHub Classroom come with an invitation link posted on Ed Discussion or the Schedule page.
- Open the invitation link and accept it — this creates your own copy of the assignment repository
- Clone your repository the same way as any other repository (Step 3 above)
- Commit and push your work before the deadline
Grading is based on the state of the main branch at the deadline. Push early and often rather than only once at the end.
9. GitHub Desktop
If you prefer a graphical interface over the command line, GitHub Desktop provides the same clone/commit/push/pull workflow through buttons:
It is especially useful for visually reviewing a diff before committing. The terminal commands in this tutorial still work identically and are what TAs will assume during office hours.
10. Common problems
“Nothing to commit”
This means Git sees no staged changes. Confirm the file was saved, then check status and stage it:
git status
git add -APush rejected because the remote has newer commits
Pull first to integrate the remote changes, resolve any conflicts, then push again:
git pull
git pushYou are not sure what Git is about to do
Run git status and git diff before git add or git commit. When in doubt, ask on Ed Discussion or in office hours rather than running commands you do not understand.
Good habits
- Commit small, logical changes with clear messages
- Pull before you start working, push when you finish a session
- Never commit large datasets or trained model weights — add them to
.gitignoreinstead - Never commit passwords, tokens, or API keys