EQC · Intake 26.13 · Version control

Git & GitHub Cheat Sheet

Save your work, undo mistakes, and share code without emailing zip files.

Section 1

What Git actually is

Save points for your code.

Think of a video game. You play for a while, then you save. If the next bit goes badly, you reload the save and try again. Git is that, for code.

Repository (repo)

Your project folder, with Git watching it. One repo per website.

Commit

One save point, with a note saying what you changed. You can always go back to one.

GitHub

The website your repo gets backed up to, so it's safe and other people can see it.

Git ≠ GitHub. Git is the program on your computer that takes the save points. GitHub is the website that stores them online. You can use Git without GitHub — but don't, because then your only copy lives on one laptop.

Section 2

Install & set up

You do this once, then never think about it again.

1

Install Git

Download it from git-scm.com/downloads. Accept every default in the installer.

Prefer buttons to typing? Install GitHub Desktop instead — it does everything on this page with clicks.

2

Tell Git who you are

Every save point gets stamped with your name. Open a terminal (in VS Code: Terminal → New Terminal) and run these two lines:

git config --global user.name "Your Name"
git config --global user.email "you@example.com"
3

Make a GitHub account

Sign up at github.com/signup. Use your real name — employers look at this. Use the same email you just put in the config.

Section 3

The daily loop

Four commands. This is 95% of Git.

You do this every time you finish a chunk of work — roughly once or twice a class.

git status                    # 1. what have I changed?
git add .                     # 2. pick up all those changes
git commit -m "Add navbar"    # 3. take the save point
git push                      # 4. send it to GitHub

git status

Lists what you've changed since the last save. Run it whenever you're unsure — it never changes anything, so it's always safe.

git add .

Gathers up your changes ready to save. The . means "this whole folder".

git commit -m "..."

Takes the save point. The message goes in the quotes — write what you did, not what you touched.

git push

Uploads your save points to GitHub. Until you push, they only exist on your laptop.

Writing a good commit message

Do this

  • Add contact form to about page
  • Fix navbar overlapping on mobile
  • Swap placeholder images for real ones

Not this

  • update
  • stuff
  • asdfgh

Section 4

Command reference

Everything else you might need this course.

Starting a project

CommandWhat it does
git clone <url>Download someone's repo to your machine. This is how you get the class repos.
git initStart watching the folder you're in. Only for brand-new projects.
git remote -vShow which GitHub repo this folder is linked to.

Everyday work

CommandWhat it does
git statusWhat have I changed?
git add .Stage every change in this folder.
git add index.htmlStage just one file.
git commit -m "msg"Take a save point.
git pushUpload save points to GitHub.
git pullDownload changes from GitHub. Run it before you start work.
git log --onelineList your save points, newest first.
git diffShow exactly what changed, line by line.

Branches (later weeks)

CommandWhat it does
git branchList branches. The * is where you are.
git switch -c new-ideaMake a branch and jump to it — try something risky without breaking your main copy.
git switch mainGo back to the main branch.
git merge new-ideaBring the branch's work into where you are now.

Section 5

When it goes wrong

It will. Everyone's does. Here's the way out.

"I broke a file and want it back"

Throw away your unsaved changes to one file:

git restore index.html

"Wrong commit message"

Rewrite the last one — only if you haven't pushed yet:

git commit --amend -m "Better message"

"I committed but shouldn't have"

Undo the commit, keep the work:

git reset --soft HEAD~1

"push was rejected"

Someone changed GitHub since you last pulled. Get their work first:

git pull
git push

The nuclear option. If a repo is truly tangled and you've pushed your work: copy your files somewhere safe, delete the folder, git clone it fresh, and paste your files back. Not elegant, but it works and it takes two minutes. Oh Sh!t, Git!? covers the elegant fixes.

Section 6

Practise

Git only clicks once you've broken it a few times.

Learn Git Branching

Visual and game-like. The single best way to make branching make sense.

GitHub Hello World

The official first-repo walkthrough. Fifteen minutes start to finish.

Pro Git

The free reference book. Chapters 1–3 cover everything in this course.

GitHub's own cheat sheet

One-page PDF. Print it and stick it next to your monitor.