0.8 Git II: GitHub¶
Suggested time: 1–2 lessons · You need: Chapter 0.7
What you will do¶
Put your repository on GitHub, so your work is backed up and you can use it on more than one computer. Then use branches to try ideas safely. By the end of this chapter you will be able to:
- create a private repository on GitHub and connect your local repository to it;
- sign in to GitHub from the command line;
pushyour commits up, andcloneandpullthem down;- make a branch, merge it, and fix a merge conflict;
- get a game series' code into your own repository;
- use
git bisectto find which commit broke a program.
Key vocabulary¶
| Term | Meaning | Example |
|---|---|---|
| GitHub | A website that stores Git repositories online | github.com |
| Remote | A copy of your repository somewhere else, usually GitHub | origin |
| Push / pull | Send your commits to the remote / fetch its commits into yours | git push, git pull |
| Clone | Download a complete copy of a repository, with its history | git clone … |
| Branch | A separate line of development | save-game |
| Merge | Combine one branch's commits into another | git merge save-game |
| Merge conflict | Both branches changed the same lines, so Git needs you to choose | <<<<<<< markers |
| Pull request | On GitHub, a request to merge a branch, where the changes can be reviewed first | "Add save game" |
The big idea: a copy somewhere safe¶
Git on your computer keeps your history, but only on that computer. GitHub keeps a copy online: if your laptop dies, your work doesn't. You can work at school and at home, and share code with your teacher.
Before you start
- Age: GitHub's Terms of Service require account holders to be at least 13. Check the current terms on GitHub.
- School policy: follow your school's rules about online accounts and where your work may be stored.
- Keep coursework private: make repositories private unless your teacher tells you otherwise. Never make your NEA public.
Step 1: Create an account and a private repository¶
- Sign up at github.com. Use an email you will keep, and turn on two-factor authentication when GitHub offers it.
- Click New repository. Name it (for example
castle-adventure), choose Private, and don't tick "Add a README", because your local repository already has commits. - GitHub shows the repository's address, like
https://github.com/alex-smith/castle-adventure.git.
Step 2: Connect and push¶
In your project folder:
What's happening?
git remote add origin … gives the GitHub copy a short name, origin. git push -u origin main sends your main
branch there; -u remembers the link, so afterwards plain git push is enough.
Signing in¶
The first time you push, Git asks you to sign in. GitHub does not accept your account password here, and hasn't since 2021. Use one of these instead:
Git for Windows includes Git Credential Manager. When you push, a window opens and you sign in through your browser. Your sign-in is then remembered.
Another option is a personal access token: create one on GitHub under Settings → Developer settings, and paste it when Git asks for a password. Treat it like a password: never put it in your code or in a commit.
Checkpoint
Refresh your repository's page on GitHub. Your files and your commit messages are there.
Step 3: The daily routine¶
| When | Command |
|---|---|
| Start of a session (get anything you pushed from another computer) | git pull |
| Something works | git add … then git commit -m "…" |
| End of a session | git push |
To get your repository onto a new computer:
This makes a folder called castle-adventure with every file and the whole history.
Step 4: Getting a game series' code¶
There are three ways to start a game series in your own GitHub repository. Your teacher will tell you which to use.
Your teacher puts a series' code pack on GitHub as a template repository.
- Open the link your teacher gives you and click Use this template → Create a new repository.
- Choose Private and create it. You get your own copy, starting with a single fresh commit.
git cloneit to your computer and work as normal.
Some teachers use a service that hands out assignments and marks them automatically, such as Classroom 50 or CodeGrade.
- Open the invitation link your teacher gives you and sign in with your GitHub account.
- The service makes a private repository for you, already containing the starting code.
git cloneit and work as normal. Eachgit pushhands your latest work in, and on some services the automatic tests run every time you push, so push when your code works.
- Unzip the code pack (for example
Rivet_Rush_code_pack.zip). - Copy the stage folder you're starting from into a new project folder.
git init, add a.gitignore(Chapter 0.7), thengit add .andgit commit -m "Start from Stage 1".- Create an empty private repository on GitHub and push to it (Step 2).
What happened to GitHub Classroom?
GitHub Classroom was GitHub's own service for handing out assignments. GitHub closed it on 28 August 2026 and named two replacements: Classroom 50, which is free and open source, and Codio, which is paid. Other services, such as CodeGrade, do a similar job. Template repositories (Option A) are an ordinary GitHub feature and were not affected.
Let your teacher see your work
On your repository's page, go to Settings → Collaborators and add your teacher's GitHub username.
Step 5: Branches, to try ideas safely¶
A branch lets you try something without risking the working version on main.
This creates a branch called save-game and moves onto it. Commit as normal. When the feature works, go back to main and merge it in:
If the idea didn't work, just switch back to main and carry on; the branch doesn't affect it.
Concept: branches
How it works: a branch is a named line of commits. main keeps going while you commit on your branch; merging
combines the two lines.
Why we use it: you can try risky changes, or work on two features at once, and main always stays working.
Where else it's used: in teams, every feature and every bug fix gets its own branch, reviewed through a pull request before it's merged.
Step 6: Fixing a merge conflict¶
If both branches changed the same lines, Git can't decide which to keep:
Auto-merging main.py
CONFLICT (content): Merge conflict in main.py
Automatic merge failed; fix conflicts and then commit the result.
Git marks the clash inside the file:
<<<<<<< HEAD
health = 50
print("Health:", health)
=======
health = 100
print("You have", health, "health")
>>>>>>> save-game
The part between <<<<<<< HEAD and ======= is the version on your current branch; the part between ======= and
>>>>>>> save-game is the incoming one. Edit the file so it's what you want (perhaps some of each), delete all three
marker lines, then:
To give up on a merge part-way through and go back to how things were: git merge --abort.
Step 7: Pull requests, issues and tags¶
These are all on the GitHub website:
- Pull requests: push a branch (
git push -u origin save-game) and GitHub offers to open a pull request. It shows every change, lets someone comment, and merges with one click. It's a useful habit even on your own, because you review your work before it goes intomain. - Issues: a to-do list attached to the repository. Record bugs and ideas as you find them.
-
Tags mark a version worth keeping, such as the one you hand in:
Step 8 (A Level): git bisect, a binary search through history¶
Your game worked a few commits ago and is broken now. Which commit broke it? git bisect finds out by binary
search: it checks out the commit halfway between a good one and a bad one, you say whether it works, and the range
halves each time. It's the same algorithm as the binary search in the high-score stages (for example Last Bastion Stage 12).
git bisect start
git bisect bad # the current commit is broken
git bisect good ad65b4b # this older commit worked
Git checks out a commit in the middle. Test it, then type git bisect good or git bisect bad, and repeat. With a test
file that exits with an error when the game is broken, Git can do all of it for you:
Finish with git bisect reset to return to where you were.
Concept: why bisect is fast
With 1,000 commits, checking each one in turn could take 1,000 tests. Binary search needs about log₂ 1000 ≈ 10. It's the difference between O(n) and O(log n), which you will measure yourself in Part 2B.
Git and your NEA¶
A private GitHub repository, committed to little and often with clear messages, gives you a dated record of how your project developed: every prototype, every fix, every change of plan.
The rules for your NEA
The H446 specification (version 3.0) says the work must be your own, with other sources properly referenced and any AI use acknowledged (sections 4d and 4e), and that evidence "must be able to be assessed without the use of any specific hardware or software" (section 3i). So a GitHub history supports your report; it doesn't replace it: put annotated screenshots of it in the report. Check your school's policy on where coursework may be stored. Keep the repository private, and add your teacher as a collaborator if they need to see it.
GitHub Desktop¶
If you prefer buttons, GitHub Desktop (desktop.github.com) does commit, push, pull and branches with a graphical interface. It runs the same Git underneath, so everything in these two chapters still applies.
Troubleshooting¶
| What you see | What to try |
|---|---|
Support for password authentication was removed |
Use Git Credential Manager, gh auth login, or a personal access token (Step 2). |
remote: Repository not found |
Check the address, and that you are signed in to an account that can see the (private) repository. |
rejected … (fetch first) when pushing |
GitHub has commits you don't have (perhaps from another computer). Run git pull, then git push. |
error: remote origin already exists |
The remote is already set. Check it with git remote -v. |
CONFLICT (content) |
See Step 6. |
Check your understanding¶
- What is the difference between
git pushandgit pull? - Why should you never paste a personal access token into your code?
- Explain why working on a branch is safer than working directly on
main. - (A Level) A project has 500 commits and the bug appeared somewhere among them. About how many tests does
git bisectneed, and why?
Answers
git pushsends your new commits to the remote (GitHub);git pullfetches commits from the remote and merges them into your copy.- Anyone who can read the code, including everyone who can see the repository and its history, could use the token to act as you on GitHub.
mainkeeps the last working version. If the experiment on the branch fails, you switch back tomainand nothing is lost.- About 9, because log₂ 500 ≈ 9. Each test halves the range of commits that could contain the bug.
Summary¶
- GitHub stores your repository online. Make coursework repositories private.
- Connect with
git remote add origin …, thengit push -u origin main. Sign in with Git Credential Manager,gh auth loginor a token, never your password. - Daily routine:
git pull→ work and commit →git push. - Start a series from your teacher's template or from the code pack yourself.
- Try ideas on a branch;
mergewhen they work; fix conflicts by editing the marked lines. git bisectuses binary search to find the commit that introduced a bug.