🧠 Command Recall Drill
Reading a command once doesn’t make it stick. Getting quizzed on it does.
How to Actually Use This Page
This isn’t a cheat sheet to skim — it’s a drill. For each scenario below:
- Read the scenario only. Don’t look at the answer yet.
- Say the command out loud (or type it into a real terminal, in a real throwaway repo —
see Setting Up a Practice Repo below).
- Then click to reveal the answer and check yourself.
- Got it wrong or hesitated? Put a mark next to it. Come back to only the marked ones
tomorrow. That’s spaced repetition — it’s the actual reason this page exists instead of just
pointing you back at the modules.
[!TIP]
Do 10-15 of these a day, not all 60 in one sitting. Cramming produces recognition (“oh yeah, I
read that”). Spaced, active recall produces the real thing — being able to type the command
without thinking, mid-incident, six months from now.
🏗️ Setting Up a Practice Repo (Do This Once)
Every drill below assumes you have a real, disposable folder to actually type these commands
into — not just read them.
mkdir ~/git-drill && cd ~/git-drill
git init
echo "# Git Drill" > README.md
git add README.md
git commit -m "initial commit"
Keep this folder around for the whole course. Break it, fix it, delete branches, force-push into
the void — it’s disposable, that’s the point.
Module 00-01 — Foundations & Fundamentals
You just started a new project folder. Turn it into a Git repo.
```bash
git init
```
Set your name and email globally, once, for every repo on this machine.
```bash
git config --global user.name "Your Name"
git config --global user.email "you@example.com"
```
You edited 3 files but only want to commit 1 of them.
```bash
git add path/to/the-one-file.js
git commit -m "message describing just that change"
```
You want to see exactly what's changed before you stage anything.
```bash
git status
git diff
```
Stage a file interactively, chunk by chunk (not the whole file at once).
```bash
git add -p
```
You need to switch branches urgently but have uncommitted work you're not ready to commit.
```bash
git stash
```
Bring back the most recent stash and remove it from the stash list.
```bash
git stash pop
```
Create a new branch AND switch to it, in one command.
```bash
git checkout -b feature/my-branch
```
See the last 5 commits, one line each.
```bash
git log --oneline -5
```
See history as a visual branch graph.
```bash
git log --graph --oneline --all
```
Mark the current commit as a release, with its own message.
```bash
git tag -a v1.0.0 -m "First stable release"
```
Module 02 — Git + GitHub
Generate a new SSH key for GitHub authentication.
```bash
ssh-keygen -t ed25519 -C "your_email@example.com"
```
Verify your SSH connection to GitHub actually works.
```bash
ssh -T git@github.com
```
Connect a local repo to a GitHub repo for the first time.
```bash
git remote add origin git@github.com:username/repo.git
```
Push a branch to GitHub for the first time (and set up tracking).
```bash
git push -u origin branch-name
```
Check what's new on the remote WITHOUT touching your local files.
```bash
git fetch origin
```
Download AND merge new remote commits into your current branch, in one step.
```bash
git pull origin main
```
Push, but safely refuse if the remote has changes you haven't seen (safer than --force).
```bash
git push --force-with-lease
```
Module 03 — Contributing to Open Source
You forked a repo on GitHub. Bring YOUR fork down to your machine.
```bash
git clone git@github.com:yourusername/their-repo.git
```
Add the ORIGINAL repo as a second remote so you can stay in sync with it.
```bash
git remote add upstream git@github.com:original-owner/their-repo.git
```
Sync your fork's main branch with the real project's latest changes.
```bash
git fetch upstream
git checkout main
git merge upstream/main
```
Module 04 — Undo & Recovery (the one to actually memorize cold)
You need to undo a commit that's ALREADY been pushed and pulled by teammates.
```bash
git revert
```
</details>
Undo your last commit, keep the changes staged, ready to re-commit.
```bash
git reset --soft HEAD~1
```
Undo your last commit, keep the changes but unstage them.
```bash
git reset --mixed HEAD~1
```
Undo your last commit and discard the changes completely (dangerous — know this one cold).
```bash
git reset --hard HEAD~1
```
You just committed but the message has a typo. Not pushed yet.
```bash
git commit --amend -m "corrected message"
```
You forgot to add a file to your last commit. Not pushed yet.
```bash
git add forgotten-file.js
git commit --amend --no-edit
```
Replay your branch's commits on top of the latest main, for clean linear history.
```bash
git rebase main
```
You ran reset --hard and think you lost work. First command, always.
```bash
git reflog
```
Found the lost commit in reflog. Bring it back safely without touching your current branch.
```bash
git branch recovery-branch HEAD@{1}
```
Apply one specific commit from another branch onto your current branch.
```bash
git cherry-pick
```
</details>
---
## Module 05 — Advanced Git
You accidentally committed a file before adding it to .gitignore. Stop tracking it going forward.
```bash
git rm --cached .env
```
Set up Git LFS to track a large binary file type.
```bash
git lfs install
git lfs track "*.psd"
```
Sign a single commit manually.
```bash
git commit -S -m "message"
```
Export your last commit as a portable patch file.
```bash
git format-patch -1 HEAD
```
Bail out of a merge entirely, back to the pre-merge state.
```bash
git merge --abort
```
Clean up local references to branches that were already deleted on the remote.
```bash
git remote prune origin
```
See every branch/tag on a remote WITHOUT cloning the whole repo.
```bash
git ls-remote origin
```
---
## 🎯 Full-Speed Round (No Hints)
Once every section above feels easy, try this round cold — just the scenario, nothing else:
1. Undo a commit that three teammates have already pulled.
2. You're mid-feature, urgent bug fix needed on a different branch, work isn't commit-ready.
3. You just realized `reset --hard` was a mistake, thirty seconds ago.
4. Clean, linear history for your own not-yet-pushed branch before opening a PR.
5. Stage only part of a file's changes, not the whole file.
6. Check the remote for new commits without touching your working directory.
7. A teammate's branch was deleted on GitHub but still shows up locally.
8. You need one specific commit from `main` applied to an old release branch.
Answers
1. `git revert `
2. `git stash`
3. `git reflog`, then `git branch recovery-branch HEAD@{1}` (or `reset --hard` to that hash)
4. `git rebase main`
5. `git add -p`
6. `git fetch origin`
7. `git remote prune origin`
8. `git cherry-pick `
</details>
---