HomeGroundworkGit

From first commit to reflog rescue

What is Git really doing?

Most people learn Git as a list of commands, and that breaks the moment something goes wrong. This guide teaches the model underneath: commits are nodes in a graph, and branches are labels pointing at them.

18 chaptersabout 3 hours of reading
a3f9c1 7d21e0 c04b8a merge feature/checkout hotfix/login main ← HEAD
Time flows left to right. Every circle is a commit; every commit remembers its parent. A branch name is only a label on one of these circles — that single fact explains most of Git.

In numbers

chapters
18
parts, fresher to senior
4
diagrams
46
command examples
129
reference tables
58

Pick the door that fits today

Every chapter stands on the mental model, but you can enter anywhere.

  1. New to GitStart with the mental model, then the three areas. Those two chapters make the everyday commands make sense.Read the mental model →
  2. Something just went wrongUndoing anything shows which undo fits the job, and what each one can and cannot bring back.Open Undoing anything →
  3. An interview this weekThe interview bank has the questions with short answers, and the cheat sheet lists every command by job.Open the interview bank →

Four parts, one trail

Each part is its own trail. A tick marks every chapter you have read.

Foundations

What a repository really is, and the commands you use every day.

5 chapters

  1. The mental modelSnapshots, a graph of commits, and branches that are only pointers. Everything else follows from these three.
    10 min
  2. What Git actually storesA key-value store of four object types, named by the hash of their contents, with a thin layer of pointers on top.
    12 min
  3. The three areas (plus the remote)Your files, the index and the repository. Most commands just copy content from one of these to another.
    9 min
  4. Setup and configurationTen minutes of setup per machine: who you are, how you log in, and the defaults Git should have shipped with.
    12 min
  5. The everyday commandsThe loop you run hundreds of times a week, and the history-reading tools that turn "who changed this?" into a one-liner.
    8 min

Working together

Branches, remotes, merging, rebasing and how teams ship through pull requests.

6 chapters

  1. Branches, HEAD, and detached HEADA branch is a 41-byte file that names a commit, and HEAD is a file that names a branch. Everything else follows.
    9 min
  2. Remotes and syncingA remote is a URL with a nickname, and origin/main is your cached memory of it. fetch, pull and push only move refs and objects between the two.
    9 min
  3. Merging and conflictsEvery merge compares three snapshots: yours, theirs, and the commit where they split. Conflicts are what is left when that comparison has no single answer.
    12 min
  4. Rebase — the one people fearRebase does not move commits. It makes new copies of them on a new base and moves the branch label to the copies.
    11 min
  5. Pull requests and GitHubHow a change gets from your branch into main on GitHub: forks, reviews, protection rules, merge queues, the three merge buttons and the gh CLI.
    14 min
  6. Team workflowsTrunk-based, GitHub flow and GitFlow compared, and how release branches, feature flags and CI gates fit around them.
    9 min

Rescue

Undo anything, find the commit that broke it, and survive the dangerous moments.

3 chapters

  1. Undoing anythingPick the right undo for the job: restore, reset, revert, amend or reflog, and know what each one can and cannot bring back.
    12 min
  2. Detective toolsFind the commit that broke it, the reason a line exists, and the history of one function, then move fixes between branches.
    11 min
  3. Danger zoneLeaked secrets, force-push accidents, commands that eat work, and how to come back from each one.
    9 min

Mastery

Clean history, very large repositories, the interview bank and the cheat sheet.

4 chapters

  1. Commit hygieneSmall commits, messages that explain why, hooks that catch mistakes early, and tags that mark what shipped.
    9 min
  2. Scale and edge casesWhat to reach for when the repository gets huge, the files get binary, and the team spans three operating systems.
    12 min
  3. Interview bankQuestions interviewers actually ask, from fresher to senior, with short answers you can defend under follow-up.
    19 min
  4. Cheat sheetEvery command worth knowing, grouped by the job you're doing, plus the setup to run once per machine.
    8 min

Three honest notes

  • Nothing on this site runs Git for you. Every example is a command to try in your own terminal, in a throwaway repository.

  • The pull request chapter uses GitHub and its gh command line. Other hosts use the same ideas under different names.

  • You do not need all of it. The first part covers the daily work, and the later parts are for the days you need them.