The Walkthrough
Do these in order. Every command is a copy button, but type them out at least the first few times, because typing is how they stick. Tick each step as you finish it.
A progress code is one line of text that carries your ticks, quiz answers, practical record and badges. Paste it into this page on another computer. There's no account and no server: nothing you do here leaves your browser.
The Four Places
This is the whole mental model. A change to a file lives in exactly one of four places, and every Git command just moves it one step. Type commands below and watch it move: it's a simulation, so nothing here can break anything.
Working Directory
Staging Area
Local Repository
.git folder. Permanent history, your machine only.GitHub
Not sure what to type? Press that button as many times as you like: it always runs the next sensible command and will walk you all the way to GitHub. Or ignore it and type your own.
Boxes 1 to 3 all live on your own machine: you can do everything so far on a plane with
the wifi off. Only git push crosses into box 4, and only git fetch
and git pull come back the other way.
Press Someone edits on GitHub above to see what
happens when box 4 gains a commit you don't have: it's the exact situation you'll create
on purpose in Step 07, and the reason git push sometimes refuses.
There are three files here on purpose. Edit two of them, then
git add only one, and look at boxes 1 and 2: one file is in the
basket, the other is still just changed. Your next commit takes the basket and leaves the
rest behind.
That is the whole answer to "why doesn't
git commit just save everything?" You fixed a bug and renamed a variable in the
same sitting; those are two different commits, and the basket is how you separate them.
Now press Create secrets.env, then
Add .gitignore, and watch the secret disappear from Git's view entirely.
Then try git add secrets.env and read what it says.
Run git add, then git diff: nothing appears, and
you assume it broke. It didn't. Plain git diff compares box 1 against box 2, and
after staging they're identical. The question you meant to ask is
git diff --staged, which compares box 2 against box 3. Try both above.
Merge vs Rebase
Two ways to bring a branch back together with main. Press the
buttons and watch what happens to the commits, especially to their names.
| git merge | git rebase | |
|---|---|---|
| Does what | Ties both lines together with one new merge commit | Copies your commits on top of the newest main |
| Your commit IDs | Unchanged | All new. Same changes, different commits |
| History shows | What actually happened | A tidier story that isn't literally true |
| Then push is | Normal | Rejected: needs --force-with-lease |
| Safe on a shared branch? | Yes | No |
While you're the only person on the repo, this choice barely matters: you
can't disrupt anyone. Use merge; it's the safe default and it's what the buttons
on GitHub do. Learn rebase now so the word isn't scary later, but don't agonise
over it. The one rule that will matter the day you work with someone:
never rebase a branch other people have already pulled.
Reading a Conflict
A conflict is not an error and you have not broken anything. It's Git saying: the same line changed in two places and I won't guess which one wins. It's the one moment Git refuses to be clever.
In a merge, HEAD is your side. In a
rebase, HEAD is the other side and your work
is on the bottom. They're swapped.
How to tell which you're in: look at the bottom
marker. A branch name means merge. A commit ID and message means rebase.
Or just run git status: it says so on the first line.
Fixing one, start to finish
| Step | What you do |
|---|---|
git status | See which files conflict and which operation you're in |
| Open the file | Delete all three marker lines and leave the content you want. Keep one side, both, or write something new: Git has no opinion |
git add <file> | This is how you say "resolved". There is no separate resolve command |
git commitor git rebase --continue | Finish the operation |
git merge --abort and git rebase --abort put everything back
exactly as it was, as if you never started. You can always back out.
When It Breaks
Every one of these is normal and none is a disaster. The goal is that red text stops meaning "I've broken it" and starts meaning "Git is telling me something".
| What you see | What it means | What to do |
|---|---|---|
warning: LF will be replaced by CRLF | Windows vs Mac/Linux line endings | Nothing. It's harmless. It is not an error |
fatal: not a git repository | You're in the wrong folder | cd into your project folder and try again |
Please tell me who you are | You skipped the name/email setup | The two git config --global lines in Step 01 |
The current branch has no upstream branch | First push of a brand new branch | Read the message: it prints the exact command. Run that |
Updates were rejected... remote contains work you do not have | GitHub has commits you don't (you edited on the website) | git pull, fix any conflict, then push |
fatal: Need to specify how to reconcile divergent branches | Your laptop and GitHub both have commits the other lacks, and Git won't guess how to combine them | git pull --no-rebase merges them. git config --global pull.rebase false makes that the default |
fatal: Not possible to fast-forward, aborting | The same thing, on a Git set to only ever fast-forward | git pull --no-rebase still merges |
refusing to merge unrelated histories | You made the GitHub repo with a README, so it has its own history | git pull origin main --allow-unrelated-histories |
failed to push some refs after a rebase | Expected: the commit IDs changed | git push --force-with-lease |
| A text editor opened and you're stuck | Git wants a commit message | Type it, save, close the tab/window. In Vim: Esc then :wq then Enter |
Support for password authentication was removed | Passwords stopped working in 2021 | On Windows, let the browser window sign you in. On a Mac or Linux, run gh auth login, or paste a personal access token where it asks for the password (Step 04) |
Permission denied on push | Signed in as the wrong account | Check the repo is yours, and which account your computer saved. If you signed in with gh, gh auth status tells you |
| Everything is on fire | - | git merge --abort / git rebase --abort, or see git reflog in Step 08 |
Beginners are scared of Git because they think they can permanently destroy their work.
Once a change is committed, it is very hard to lose: git reflog
remembers roughly 90 days of everything you did, even things you "deleted".
One real exception: git reset --hard destroys changes
you hadn't committed, and nothing brings those back. Which is the whole argument for
committing early and often. A commit is a save point.
Every Command
Everything on this page, plus a bit more. Filter by name or by what you're trying to do: try typing "undo" or "branch".
Check Yourself
Seven questions on the things that actually catch people out. Getting one wrong is the useful outcome: each answer explains itself.
The Practical
Eleven tasks. Nobody tells you the commands: you have to do it. This is a sandbox, so a wrong move costs you nothing: get it wrong as many times as you like. That is the entire point of practising here rather than on something that matters.
Stuck on the command itself? Every Command has the lot, and looking it up is a legitimate way to work, not cheating.
Adding Player 2
Everything above works alone. The moment a second person joins, four new ideas show up. This is a map, not a lesson: come back when you actually have someone to work with.
| Idea | What changes |
|---|---|
| Collaborators | Settings → Collaborators → Add people. They must accept the invite before they can push: this is the single most common ten-minute stall |
| Forks | For people you don't want pushing to your repo. They copy it, work there, and send a pull request back. This is how you contribute to strangers' open-source projects |
| Review | Now your pull request has an audience. Someone clicks a line and comments. You cannot approve your own PR: that's the point of it |
| Real conflicts | Now they happen by accident instead of on purpose. Nothing new to learn (you already did this in Step 07), but git pull before you start work becomes a habit rather than a nicety |
Write commit messages as if a stranger will read them, because in six months you are that stranger. "Fix bug" tells you nothing. "Fix crash when the search box is empty" tells you everything. This is the single habit that separates people who are comfortable in a codebase from people who aren't, and you can practise it entirely alone.
Badges
These mean absolutely nothing. Collect them anyway. Most are for trying, being wrong and coming back, because getting stuck is most of learning Git.