Git and GitHub
A save system for code. Go back in time, see every change, and back up your work online.
Learn it
Git saves snapshots called commits. GitHub keeps a copy online.
Git is a version control system: it takes snapshots of your project called commits. Each commit has a message saying what changed. If you break something, you can look back at, or return to, any earlier commit. Almost every software team in the world uses Git.
The everyday cycle has three steps: change files, stage the changes you want to save (git add), then commit them with a message (git commit -m "..."). A folder tracked by Git is called a repository (repo).
GitHub is a website that stores copies of Git repositories online, so your work is backed up and you can share it. Uploading commits is called pushing. VS Code can publish to GitHub with one button.
- Install Git. In Terminal run the command below, or download the installer from git-scm.com (the default options are fine; when asked for an editor, you can choose VS Code).
winget install -e --id Git.Git
- Open a new terminal and check it worked:
git --version
You should see something likegit version 2.51.0.windows.1
- Type the check command. If Git is missing, macOS offers to install the Command Line Developer Tools: click Install and wait.
git --version
You should see something likegit version 2.39.5 (Apple Git-154)
With Homebrew you can also runbrew install git.
- Install Git:
sudo apt install -y git
- Check it worked:
git --version
You should see something likegit version 2.43.0
- Tell Git your name and email once. These appear on your commits (on all systems):
git config --global user.name "Your Name"
git config --global user.email "you@example.com"
- In your
vault_breakerfolder, turn it into a repository:git init
- Tell Git to ignore the virtual environment (it is big and can be rebuilt from requirements.txt). Create a file called
.gitignorein VS Code containing this line:.venv/
- Stage everything and make your first commit:
git add .
git commit -m "First commit: hello.py and setup"
- See your history:
git log --oneline
You should see something like3f9a1c2 First commit: hello.py and setup
- Back it up on GitHub (optional, and only if you are old enough): GitHub requires users to be at least 13. Create a free account at github.com with an adult's help. Then in VS Code open the Source Control panel (the branch icon) and click Publish to GitHub. Choose a private repository. VS Code opens your browser to sign in and then uploads your commits.Under 13? Skip GitHub for now. Git on your own computer still gives you the full save system.
Capture the flag
+10 XPWhich Git command saves a snapshot of your staged changes? (just the command word after git)
Create a free account to start this lab
Sign in to answer the flag question. Your progress, XP and code are saved to your account. No card needed.
Version control online
+20 XPSet up Git for your game project.
Create a free account to start this lab
Sign in to do this homework and have it checked. Your progress, XP and code are saved to your account. No card needed.