Skip to content

0.8 Git II: GitHub

A Level (optional at IGCSE Part 1D)Part 0

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;
  • push your commits up, and clone and pull them down;
  • make a branch, merge it, and fix a merge conflict;
  • get a game series' code into your own repository;
  • use git bisect to 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 coursework or exam practice public.

Step 1: Create an account and a private repository

  1. Sign up at github.com. Use an email you will keep, and turn on two-factor authentication when GitHub offers it.
  2. 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.
  3. GitHub shows the repository's address, like https://github.com/alex-smith/castle-adventure.git.

Step 2: Connect and push

In your project folder:

git remote add origin https://github.com/alex-smith/castle-adventure.git
git push -u origin main

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.

The simplest route is the GitHub CLI. Install it (brew install gh on a Mac), then run:

gh auth login

and follow the prompts to sign in through your browser. Git will then use that sign-in.

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:

git clone https://github.com/alex-smith/castle-adventure.git

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.

  1. Open the link your teacher gives you and click Use this template → Create a new repository.
  2. Choose Private and create it. You get your own copy, starting with a single fresh commit.
  3. git clone it 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.

  1. Open the invitation link your teacher gives you and sign in with your GitHub account.
  2. The service makes a private repository for you, already containing the starting code.
  3. git clone it and work as normal. Each git push hands your latest work in, and on some services the automatic tests run every time you push, so push when your code works.
  1. Unzip the code pack (for example Rivet_Rush_code_pack.zip).
  2. Copy the stage folder you're starting from into a new project folder.
  3. git init, add a .gitignore (Chapter 0.7), then git add . and git commit -m "Start from Stage 1".
  4. 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.

git switch -c save-game

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:

git switch main
git merge save-game

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:

Output
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:

main.py
<<<<<<< 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:

git add main.py
git commit -m "Merge save-game"

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 into main.
  • 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:

    git tag v1.0
    git push --tags
    

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:

git bisect run python3 test_game.py
Output (end)
5e1f10c… is the first bad commit
    Step 4

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 projects

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 Cambridge A Level has no coursework project, but a history like this is still the best way to keep your practice programs safe, and to see how far you've come.

Your own work

Keep your repositories private, and follow your school's rules on where your work may be stored and on using other people's code or AI tools. In the Paper 4 exam itself you work on a computer with no internet, so practise without GitHub's help too (Chapter 52).

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

  1. What is the difference between git push and git pull?
  2. Why should you never paste a personal access token into your code?
  3. Explain why working on a branch is safer than working directly on main.
  4. (A Level) A project has 500 commits and the bug appeared somewhere among them. About how many tests does git bisect need, and why?
Answers
  1. git push sends your new commits to the remote (GitHub); git pull fetches commits from the remote and merges them into your copy.
  2. 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.
  3. main keeps the last working version. If the experiment on the branch fails, you switch back to main and nothing is lost.
  4. 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 …, then git push -u origin main. Sign in with Git Credential Manager, gh auth login or 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; merge when they work; fix conflicts by editing the marked lines.
  • git bisect uses binary search to find the commit that introduced a bug.
This is a free sample: log in for every book →