Skip to content

Git

Git, GitHub, and the workflow around them: branching, review, commit history, and getting yourself out of trouble. Part of the Frontend Roadmap. See also Deployment for the CI pipelines built on GitHub Actions, and Tooling for the monorepo tools referenced below.

Learning the commands takes an afternoon. What costs people time in their first job is everything around them: which branch to start from, how to keep it current, what belongs in a single commit, what a reviewer needs from a pull request, and how to undo something that is already pushed. The Learn section covers the commands; everything after it covers working with other people.

Learn

  • Pro Git — The official book, free in full, and still the best single explanation of Git there is.
  • Learn Git Branching — Branching, merging, and rebasing taught by moving nodes around an animated commit graph.
  • Git How To — Guided tour that walks through the fundamentals of Git.
  • Atlassian Git Tutorials — Tutorials covering the commands and the workflows, with the clearest writing on rebasing anywhere.
  • GitHub Skills — Short interactive courses that run as real pull requests in a repository of your own.

Reference

Documentation and cheat sheets

  • Git Documentation — Reference page for every command, and the place to check what a flag really does.
  • Git Cheat Sheet — GitHub’s one-page PDF of the commands you use daily. Kept as the only cheat sheet here because it is printable and does not go stale.
  • Git Command Explorer — Finds the command from what you are trying to do, rather than the other way round.

Git’s model

Git stops being magic once you know that a commit is a snapshot plus a pointer to its parent, and that a branch is a file containing one commit ID. Merge, rebase, reset, and cherry-pick are all just moving those pointers, which is why the reading below pays for itself.

  • Git Objects — The object store — blobs, trees, and commits — built up by hand from plumbing commands.
  • Commits Are Snapshots, Not Diffs — The most useful correction to the way most people picture a commit.
  • Git From the Inside Out — Walks the graph as it changes, command by command, down to the files on disk.
  • Visualize Git — Git visualizations powered by D3, driven by commands you type yourself.

Everyday workflow

  • Recording Changes to the Repository — Staging, committing, and diffing, and what the index is actually for.
  • Working with Remotes — Fetch, pull, push, and the tracking relationship between a local branch and its remote.
  • Stashing and Cleaning — Parking half-finished work so you can switch branches without committing it.
  • Ignoring Files — What belongs in .gitignore, per repository and per machine.
  • gitattributes — Line endings, diff drivers, and marking generated files, in the config file everyone forgets exists.

Branching and collaboration

The short version of the argument: rebase your own branch to keep it current and to tidy it before review, merge it into the trunk when it is ready, and never rebase a branch someone else has already pulled.

  • GitHub Flow — Branch, commit, open a pull request, merge, delete the branch. The default for a web team.
  • Trunk Based Development — Short-lived branches merged daily, and the case against long-running release branches.
  • Merging vs Rebasing — The golden rule of rebasing, and when each of the two is the right call.
  • Branches in a Nutshell — Why a branch costs nothing, and what a fast-forward actually is.
  • Merge Conflicts — Reading the conflict markers and resolving them without guessing.

Pull requests and code review

Commit hygiene

  • How to Write a Git Commit Message — The seven rules, including why the subject line is written in the imperative mood.
  • Conventional Commits — A feat: or fix: prefix that machines can read, which is what drives changelogs and version bumps.
  • Atomic Commits — One commit per logical change, and everything that buys you months later.
  • Rewriting History — Amend, interactive rebase, squash, and reorder, before anyone else has seen the branch.
  • Pull Request Merges — Merge commit, squash, or rebase: what each option does to the history you are left with.

Fixing mistakes

You will need this section. Almost nothing is destroyed by an ordinary Git mistake: commits stay reachable through the reflog for 90 days by default, so most of what feels like lost work is a lookup rather than a loss.

  • Oh Shit, Git!?! — The mistakes everyone makes, each with the commands that undo it. The same content lives swear-free at dangitgit.com.
  • Undoing Changesreset, revert, and restore compared, with what each one touches and what it leaves alone.
  • Reset Demystified — Reset explained through HEAD, the index, and the working tree, which makes --soft and --hard obvious.
  • git reflog — The log of everywhere HEAD has been, and how a deleted branch comes back.
  • Debugging with Gitgit bisect to binary-search history for the commit that broke it, plus git blame.

GitHub

  • GitHub Actions — Workflows, jobs, and runners from the concepts up; the pipelines built on it are in Deployment.
  • Dependabot Version Updates — Automated dependency-bump pull requests, and how to keep them from becoming noise.
  • About Releases — Tags, generated release notes, and attaching build artifacts to a version.
  • Semantic Versioning — What a major, minor, or patch bump promises, which is the claim a release tag is making.
  • Issue Templates — Issue forms that collect the information you would otherwise have to ask for every time.

Advanced

  • git worktree — Several branches checked out in several directories at once, sharing one clone.
  • Submodules — How they work, and why most teams end up reaching for a published package or a monorepo instead.
  • Git LFS — Large binaries kept outside the object database, with small pointer files committed in their place.
  • Signing Your Work — GPG and SSH commit signing, and what the Verified badge on a commit is asserting.
  • monorepo.tools — What a monorepo needs from its tooling, and which tools provide it. See Tooling for the tools themselves.

Practice

  • Oh My Git! — Open-source card game that teaches the commit graph by making you repair broken repositories.
  • Git Exercises — Graded exercises checked by pushing your solution to a server that inspects the history.

Tools

  • gitignore.io — Generates a .gitignore from the languages, editors, and frameworks you name.
  • GitHub CLIgh, for pull requests, issues, releases, and Actions runs from the terminal.
  • husky — Git hooks committed to the repository, so lint and tests run before a commit lands.
  • lint-staged — Runs linters over staged files only, which is what keeps a pre-commit hook fast enough to survive.
  • commitlint — Checks commit messages against Conventional Commits, in a hook or in CI.
  • lazygit — Terminal UI for staging hunks, rebasing, and resolving conflicts without memorising flags.