Git

The undo button for your career.

▶ the lesson · narrated sketch video · tap for sound

the intro

Git is version control: a time machine for your code. Commit to save a checkpoint, branch to explore an idea safely, merge when it works, push to share. Every bug becomes recoverable, and every experiment becomes cheap.

the sample

the sacred daily ritual

git add .
git commit -m "fix stuff"
git push

# friday deploy, let’s go 😎

fun fact ✦

Git was built in ~10 days by the Linux creator after a licensing fight. Spite-driven development.

the docs

the deep dive

the ideas behind the video — concepts, diagrams, a walkthrough and the traps to avoid

Git does not store diffs of your files — it stores snapshots. Every commit is a full picture of the project (with identical parts shared behind the scenes), and a branch is just a sticky note pointing at one snapshot. Once you see commits as a graph of snapshots, merge, rebase, and reset stop being spells and become pointer moves.

commits are snapshots, branches are sticky notes

working dirstaging arealocal reporemote (GitHub)
code travels left to right — add proposes, commit saves, push publishes

key terms

commit

An immutable snapshot of the project, addressed by a hash. Change anything inside it and the hash changes.

git commit -m "add login"

staging area

The draft of your next commit. You pick changes with add, then commit records exactly what was staged.

git add -p

HEAD

A pointer to where you are right now — usually the tip of your current branch.

detached HEAD = no branch

reflog

A private journal of every move HEAD made. Deleted a branch by mistake? The commit is still in here for weeks.

git reflog

how it works

  1. 1
    Check before you act

    Run git status every time you sit down and every time you feel lost. It names your branch and exactly what changed.

  2. 2
    Stage one idea at a time

    git add -p walks you through changes hunk by hunk. Small, single-purpose commits make reviews and reverts painless.

  3. 3
    Commit with a why

    The message should say why the change exists, not restate the diff. Future you at 2 a.m. is the audience.

  4. 4
    Sync before you push

    git pull --rebase replays your work on top of the latest main. Pushing a stale branch is how surprise merge conflicts are born.

the code, explained

the daily loop, done properly

1$ git status
2$ git add -p src/auth.ts
review hunks one by one — atomic commits
3$ git commit -m "feat: add login rate limit"
4$ git pull --rebase origin main
replay your work on top, tidy history
5$ git push origin feat/login
6$ git log --oneline -3
compact history at a glance

side by side

merge

  • history stays exactly as happened
  • one extra merge commit
  • safe on shared branches
  • graph shows real branching
VS

rebase

  • replays commits on the target
  • linear, easy-to-read history
  • never on shared branches
  • conflicts handled per commit
⚠️ watch out

Git remembers everything you commit, forever. Deleting a file in a later commit does not scrub it from history — anyone can check out yesterday. If a secret hits a commit, rotate the credential first; rewriting history is cleanup, not security.

quick answers

I committed to the wrong branch. Now what?

If it is unpushed: git reset --soft HEAD~1, switch to the right branch, commit again. If pushed and shared: cherry-pick it over and revert the original.

How do I undo my last commit?

git reset --soft HEAD~1 keeps the changes staged, --hard throws them away. If the commit was already pushed to others, use revert instead.

Why is my repo so big?

History keeps every version of every file. Large binaries are the usual culprit — move assets to Git LFS and the clone shrinks dramatically.

quick hits about Git

short answers · interviews, tips, trivia & hidden gems

🎤 interview

Merge or rebase?watch ↗

🎤 interview

Reset vs revert?watch ↗

🎤 interview

Conflicts decodedwatch ↗

📚 tutorial

What never goes in gitwatch ↗

🔧 useful

Type less with aliaseswatch ↗

🔧 useful

One commit = one ideawatch ↗

💎 deep

Commits are never truly lostwatch ↗

💎 deep

Binary-search the bugwatch ↗

💎 deep

Checks before every commitwatch ↗

🧠 trivia

Git is British slangwatch ↗