Playbook

Overview

This chapter is a quick-reference collection of recipes for common Git tasks. Each recipe shows the problem, the commands to solve it, and what to watch out for.

For command syntax, see the official Git reference. For definitions, see Glossary.

Everyday

RecipeWhat you’ll find
Undoing ChangesDiscard, unstage, reset, revert, and recover lost commits
DiffingUnstaged, staged, between branches, commits, and files
HistoryLog formatting, filtering by author, date, and path
StashingSave and restore work in progress

Branching and Merging

RecipeWhat you’ll find
BranchingCreate, delete, rename, and inspect branches
MergingFast-forward, no-ff, squash, conflict resolution
RebasingLinearize history and squash commits interactively
Cherry-PickingApply individual commits across branches

Remote

RecipeWhat you’ll find
Remote OperationsPush, pull, force push safely, sync forks
Remote ManagementAdd, rename, remove remotes, switch URL, SSH setup
SSH SetupKey generation, agent, GitHub registration, troubleshooting
Bare RepositoriesCreate, clone, convert, and use bare repos as local remotes
CredentialsCredential helpers (cache, store, GCM), HTTPS tokens, security

Project Structure

RecipeWhat you’ll find
TaggingCreate, push, and delete annotated tags
SubmodulesAdd, clone, update, and remove submodules
Remove a SubmoduleStep-by-step cleanup — deinit, git rm, cached data
SubtreesAdd, pull, push, and remove subtrees
Git LFSTrack large files with pointer references and external storage

Advanced

RecipeWhat you’ll find
SelectorsTilde, caret, double-dot, triple-dot, reflog refs
HooksPre-commit, commit-msg, sharing hooks, bypassing
Pre-commit HookScript creation, common checks, sharing and bypassing
Commit-msg HookMessage validation, Conventional Commits, examples
DebuggingBisect, blame, and search commit history
Git BisectBinary search for the commit that introduced a bug
ConfigurationIdentity, defaults, aliases, and diagnostics
On this page