Git Notes & Reference Guide
The definitive developer reference for Git. Master daily commands, advanced history manipulation, branching workflows, disaster recovery with reflog, and the underlying object plumbing. Read every chapter with syntax-highlighted examples, diagrams, and modern workflow recommendations.
Explore All 61 Chapters
- Getting Started
Install Git, verify your version, initialize repositories, configure user identity, and manage remotes.
- Browsing History
Inspect commit histories using git log, formatting, graph visualization, author filters, and date ranges.
- Working with Remotes
Add, inspect, rename, update, and prune remote repositories and upstream branch tracking.
- Staging
Stage all changes, individual files, deleted files, unstage modifications, and add hunks interactively.
- Ignoring Files and Folders
Configure local and global .gitignore patterns, exceptions, subfolder rules, and untrack committed files.
- Git Diff
Compare working directory changes, staged files, branches, commits, word diffs, and patch generation.
- Undoing
Roll back commits, undo working copy changes, recover with reflog, and undo merged commits.
- Merging
Perform automatic merges, fast-forward merges, no-ff commits, merge strategies, and abort merges.
- Submodules
Clone, initialize, update, move, and remove embedded Git repositories and branch tracking.
- Committing
Craft clear commit messages, amend commits, stage selectively with patch mode, and sign with GPG.
- Aliases
Create command shortcuts, complex shell aliases, pretty log graphs, and unwatched file helpers.
- Rebasing
Rebase local branches, perform interactive rebases to squash or reword commits, and configure autostash.
- Configuration
Set default editors, auto-correct typos, manage multi-account identities, line endings, and proxies.
- Branching
Create, switch, list, delete, rename, search, and track local and remote branches.
- Rev-List
Filter and list commits between branches to verify merges and commit ancestry.
- Squashing
Combine multiple commits into one using reset, merge --squash, interactive rebase, and autosquash.
- Cherry Picking
Apply individual commits or commit ranges across branches, check redundancy, and cherry pick clean patches.
- Recovering
Recover lost commits, dropped stashes, deleted branches, and restored file versions using git reflog.
- Git Clean
Interactively or forcefully remove untracked files, ignored files, and untracked directories.
- Gitattributes
Configure automatic line ending normalization, binary file detection, and custom diff drivers.
- Mailmap & Aliases
Map author names and email aliases in .mailmap to deduplicate contributor statistics in git shortlog.
- Workflows
Compare Centralized, Gitflow, Feature Branch, GitHub Flow, and Forking collaboration models.
- Pulling
Fetch and merge remote changes, keep linear history with rebase, overwrite local, and handle permissions.
- Hooks
Automate pre-commit, commit-msg, pre-push, and post-receive validation scripts on client and server.
- Cloning Repositories
Execute shallow clones, single-branch clones, recursive submodule clones, and proxy connections.
- Stashing
Temporarily shelve dirty working directory changes, pop, apply, create partial stashes, and recover dropped stashes.
- Subtrees
Embed third-party repositories, pull updates, and backport commits using git subtree.
- Renaming
Rename directories, files, local branches, and remote-tracking branches safely.
- Pushing
Push branches, tags, specific commits, configure default push behavior, and use force-with-lease.
- Internals
Understand Git’s object store: blobs, trees, commits, annotated tags, HEAD, and symbolic refs.
- git-tfs
Bridge Git and Team Foundation Server (TFVS) with clone, checkin, pull, and push workflows.
- Empty Directories
Work around Git’s file-only tracking model using .gitkeep and directory conventions.
- git-svn
Interact with Subversion repositories: clone, dcommit, linear rebase, and empty directory tracking.
- Archive
Export clean zip and tar archives of specific commits, branches, tags, or subdirectories with git archive.
- Rewriting History with filter-branch
Bulk rewrite commit author names, emails, and dates across repository history.
- Migrating to Git
Migrate repositories from SVN, Mercurial (hg), and TFVC into Git with complete commit history.
- Show
Inspect commit details, patch diffs, tree objects, and blob contents using git show.
- Resolving Merge Conflicts
Identify conflict markers, resolve file collisions manually, and complete the merge commit.
- Bundles
Package commits and references into offline sneakernet files with git bundle.
- Gitk History Viewer
Visualize repository DAGs, commit ranges, ancestry paths, and file histories with Gitk.
- Bisecting Faulty Commits
Locate regression-introducing commits via binary search using manual or automated git bisect.
- Blaming
Inspect line-by-line file authorship, commit timestamps, line ranges, and ignore whitespace adjustments.
- Git Revisions Syntax
Master revision specifiers: SHA-1 prefixes, symbolic refs, HEAD^, HEAD~n, ranges, and text searches.
- Worktrees
Manage multiple working directories attached to the same repository simultaneously with git worktree.
- Git Remote
List, add, rename, prune, query, and configure URLs for remote tracking repositories.
- Git Large File Storage (LFS)
Track binary assets and heavy files via external pointers using Git LFS and .gitattributes.
- Git Patch
Generate email-compatible patches with git format-patch and apply changes cleanly with git apply and git am.
- Git Statistics
Analyze commit counts, lines of code per author, commit dates, and find local repositories.
- git send-email
Configure SMTP and send patch series to open source mailing lists using git send-email.
- Git GUI Clients
Compare built-in tools (gitk, git-gui) with GitHub Desktop, GitKraken, SourceTree, and SmartGit.
- Reflog & Lost Commits
Recover lost commits after erroneous rebases, accidental resets, or bad squashes using git reflog.
- TortoiseGit
Perform GUI squashing, assume-unchanged flagging, file ignoring, and branching with TortoiseGit on Windows.
- External Merge & Diff Tools
Configure external visual diff and merge tools including KDiff3, IntelliJ IDEA, and Beyond Compare.
- Update Object Name in Reference
Low-level reference updates, validation, and reflog creation using git update-ref.
- Branch Name in Bash Prompt
Customize PS1 in bash to display the active Git branch dynamically in your terminal prompt.
- Git Client-Side Hooks
Implement custom pre-push checks, WIP commit blockers, and test suite runners locally.
- Git rerere
Automate recurring merge conflict resolution across rebases with Reuse Recorded Resolution (rerere).
- Change Git Repository Name
Update local remote URLs when GitHub or Bitbucket repository names are changed.
- Git Tagging
Create lightweight and annotated tags, list, search version tags, and push tags to remotes.
- Tidying Local & Remote Repo
Prune dead remote tracking branches and clean up deleted local branches using git fetch -p.
- Git diff-tree
Compare tree objects, inspect commit modifications, and format diff output at plumbing level.
Frequently Asked Questions
What does this Git Guide cover?
All 61 chapters and 320 sections from Git Notes for Professionals: installation, branching, interactive rebasing, staging hunks, .gitignore rules, worktrees, reflog recovery, submodules, subtrees, workflows (Gitflow, GitHub Flow, Forking), hooks, and Git internals.
How do I choose between git rebase and git merge?
Use git merge when you want to preserve the complete chronological history including branch merge points. Use git rebase to maintain a clean, linear commit history before integrating feature branches into shared branches like main.
What is the difference between git checkout and git switch / git restore?
In modern Git (v2.23+), the overloaded git checkout command is split into git switch (for creating and switching branches) and git restore (for reverting working tree files and unstaging changes).
Can I recover commits that were accidentally reset or squashed?
Yes! Git maintains a local reference log (git reflog) for approximately 90 days. You can inspect git reflog to locate orphaned commit hashes and recreate branches at those points.
Is this Git handbook free and open?
Yes. The handbook is compiled from Stack Overflow Documentation and released under Creative Commons Attribution-ShareAlike (CC BY-SA 3.0). You can also download the original offline PDF directly.
Contributors & Credits
- Aaron Critchley Chapters 6
- Aaron Skomra Chapters 49
- aavrug Chapters 26
- Abdullah Chapters 2
- Abhijeet Kasurde Chapters 6
- adarsh Chapters 16
- Adi Lester Chapters 6
- AER Chapters 12, 25, 29
- AesSedai101 Chapters 4, 11, 53
- Ahmed Metwally Chapters 2
- Ajedi32 Chapters 11
- Ala Eddine JEBALI Chapters 1
- Alan Chapters 10
- Alex Stuckey Chapters 46
- Alexander Bird Chapters 12
- Allan Burleson Chapters 1
- Alu Chapters 50
- ambes Chapters 45
- Amitay Stern Chapters 1, 10
- anderas Chapters 6, 12
- AndiDog Chapters 16
- andipla Chapters 44
- Andrea Romagnoli Chapters 25
- Andrew Sklyarevsky Chapters 10
- Andy Hayden Chapters 1, 4, 7, 10, 25
- AnimiVulpis Chapters 1, 5, 14
- AnoE Chapters 24
- Anthony Staunton Chapters 11
- APerson Chapters 10, 13
- apidae Chapters 6
- Aratz Chapters 2
- Asaph Chapters 4, 26
- Asenar Chapters 11, 13
- Ates Goral Chapters 32
- Atul Khanduri Chapters 17, 59
- Bad Chapters 14
- bandi Chapters 10, 16
- Ben Chapters 5
- Blundering Philosopher Chapters 25
- BobTuckerman Chapters 14
- Boggin Chapters 1, 7, 31, 36
- Božo Stojković Chapters 5
- bpoiss Chapters 5
- Braiam Chapters 5
- brentonstrine Chapters 7, 8
- Brett Chapters 2
- Brian Chapters 1, 7
- Brian Hinchey Chapters 26
- bstpierre Chapters 11
- bud Chapters 17, 26, 28
- Cache Staheli Chapters 5, 10, 13
- Caleb Brinkman Chapters 3, 16
- Charlie Egan Chapters 6
- Chin Huang Chapters 20
- Christiaan Maks Chapters 24
- Cody Guldner Chapters 10, 29
- Collin M Chapters 5
- ComicSansMS Chapters 9
- Confiqure Chapters 4, 22, 24, 36, 44
- cormacrelf Chapters 10
- Craig Brett Chapters 1
- Creative John Chapters 18
- cringe Chapters 29
- Dániel Kis Chapters 45
- dahlbyk Chapters 20
- dan Chapters 14
- Dan Hulme Chapters 1
- Daniel Käfer Chapters 12, 14, 50
- Daniel Stradowski Chapters 14
- Dartmouth Chapters 5, 25, 34, 43, 45, 47, 48
- David Ben Knoble Chapters 38
- davidcondrey Chapters 2, 10
- Deep Chapters 10, 26
- Deepak Bansal Chapters 14
- Devesh Saini Chapters 5
- Dheeraj vats Chapters 5
- Dimitrios Mistriotis Chapters 22
- Dong Thang Chapters 49
- dubek Chapters 17
- Duncan X Simpson Chapters 14
- e.doroskevic Chapters 12, 13
- Ed Cottrell Chapters 5
- Eidolon Chapters 24
- Elizabeth Chapters 45
- enrico.bacis Chapters 5
- ericdwang Chapters 10
- eush77 Chapters 6, 11, 16
- eykanal Chapters 1
- Ezra Free Chapters 25
- Fabio Chapters 2
- Farhad Faghihi Chapters 48
- FeedTheWeb Chapters 48
- Flows Chapters 2, 24
- forevergenin Chapters 3, 14, 34
- forresthopkinsa Chapters 22
- fracz Chapters 5, 14, 26
- Fred Barclay Chapters 1, 10, 14
- frlan Chapters 29
- Functino Chapters 5
- fybw id Chapters 49, 61
- ganesshkumar Chapters 25
- gavv Chapters 14, 35
- George Brighton Chapters 10
- georgebrock Chapters 16
- GingerPlusPlus Chapters 26
- Glenn Smith Chapters 35
- gnis Chapters 19
- Greg Bray Chapters 50
- Guillaume Chapters 29
- Guillaume Pascal Chapters 5, 36
- guleria Chapters 2
- hardmooth Chapters 22
- heitortsergent Chapters 3
- Henrique Barcelos Chapters 1
- Horen Chapters 22
- Hugo Buff Chapters 48
- Hugo Ferreira Chapters 12
- Igor Ivancha Chapters 10
- Indregaard Chapters 36
- intboolstring Chapters 2, 4, 5, 6, 9, 10, 12, 17, 29
- Isak Combrinck Chapters 57
- J F Chapters 9
- Jack Ryan Chapters 6
- JakeD Chapters 6
- Jakub Narębski Chapters 4, 5, 6, 26, 43
- james large Chapters 14
- James Taylor Chapters 10
- janos Chapters 1, 2, 10
- Jarede Chapters 26
- Jason Chapters 14
- Jav_Rock Chapters 1, 45, 49
- Jeff Puckett Chapters 27
- jeffdill2 Chapters 1, 3, 6, 26
- Jens Chapters 5
- jkdev Chapters 4
- joaquinlpereyra Chapters 5
- Joel Cornett Chapters 14
- joeytwiddle Chapters 10
- JonasCz Chapters 5
- Jonathan Chapters 14
- Jonathan Lam Chapters 1
- Jordan Knott Chapters 10
- Joseph Dasenbrock Chapters 1, 14
- Joseph K. Strauss Chapters 6, 12
- joshng Chapters 5
- jpkrohling Chapters 16
- jready Chapters 2
- jtbandes Chapters 11, 12
- Julian Chapters 13, 52
- Julie David Chapters 3, 18, 26
- jwd630 Chapters 39
- Kačer Chapters 5
- Kageetai Chapters 1
- Kalpit Chapters 3, 45
- Kamiccolo Chapters 2
- Kapep Chapters 5
- Kara Chapters 26
- Karan Desai Chapters 28
- kartik Chapters 14, 25
- KartikKannapur Chapters 1, 10, 25, 48
- Kay V Chapters 1, 4
- Kelum Senanayake Chapters 56
- Keyur Ramoliya Chapters 54
- khanmizan Chapters 6, 14
- kirrmann Chapters 14
- kisanme Chapters 14, 17
- Kissaki Chapters 23, 31
- knut Chapters 5
- kofemann Chapters 49
- Koraktor Chapters 26
- kowsky Chapters 9
- KraigH Chapters 2
- LeftRight92 Chapters 5
- LeGEC Chapters 2, 12
- Liam Ferris Chapters 8
- Libin Varghese Chapters 12
- Liju Thomas Chapters 47
- Liyan Chang Chapters 13
- Lochlan Chapters 17
- lostphilosopher Chapters 24
- Luca Putzu Chapters 12
- lucash Chapters 12
- Mário Meyrelles Chapters 29
- maccard Chapters 1
- Mackattack Chapters 5
- madhead Chapters 11
- Majid Chapters 6, 10, 12, 14, 22, 26
- manasouza Chapters 2, 26
- Manishh Chapters 55
- Mario Chapters 21
- Martin Chapters 14
- Martin Pecka Chapters 5
- Marvin Chapters 5, 29
- Matas Vaitkevicius Chapters 52
- Mateusz Piotrowski Chapters 16
- Matt Clark Chapters 2, 10
- Matt S Chapters 29
- Matthew Hallatt Chapters 2, 7, 10, 42, 46
- MayeulC Chapters 5, 10, 14, 19, 23, 29
- MByD Chapters 3
- Micah Smith Chapters 10
- Micha Wiedenmann Chapters 53
- Michael Mrozek Chapters 12
- Michael Plotke Chapters 21
- Mitch Talmadge Chapters 5, 14
- mkasberg Chapters 15
- mpromonet Chapters 2, 9, 17, 23
- MrTux Chapters 41
- mwarsco Chapters 24
- mystarrocks Chapters 3
- n0shadow Chapters 19
- Narayan Acharya Chapters 5
- Nathan Arthur Chapters 4
- Nathaniel Ford Chapters 6, 7
- Nemanja Boric Chapters 12
- Nemanja Trifunovic Chapters 50
- nepda Chapters 14
- Neui Chapters 1, 5
- nighthawk454 Chapters 30, 42
- Nithin K Anil Chapters 7
- Noah Chapters 2, 8, 14
- Noushad PP Chapters 14
- Nuri Tasdemir Chapters 5
- nus Chapters 11, 38
- ob1 Chapters 1
- Ogre Psalm33 Chapters 6
- Oleander Chapters 2
- olegtaranenko Chapters 14
- orkoden Chapters 6, 40
- Ortomala Lokni Chapters 6, 12, 13, 26
- Ozair Kafray Chapters 14
- P.J.Meisch Chapters 28
- Pace Chapters 7
- PaladiN Chapters 5, 9, 14
- Patrick Chapters 26
- pcm Chapters 29
- Pedro Pinheiro Chapters 2, 50
- penguincoder Chapters 6, 8, 11
- Peter Amidon Chapters 51
- Peter Mitrano Chapters 12, 25, 26
- PhotometricStereo Chapters 28
- pkowalczyk Chapters 25
- pktangyue Chapters 5
- Pod Chapters 1, 10
- pogosama Chapters 29
- poke Chapters 5
- Priyanshu Shekhar Chapters 13, 14, 19, 42
- pylang Chapters 5, 12
- Raghav Chapters 3
- Ralf Rafael Frix Chapters 3, 14, 19, 26
- RedGreenCode Chapters 17
- RhysO Chapters 5
- Ricardo Amores Chapters 33
- Richard Chapters 12
- Richard Dally Chapters 4
- Richard Hamilton Chapters 14
- Rick Chapters 5, 7, 10, 25, 36
- riyadhalnur Chapters 11
- Roald Nefs Chapters 1
- Robin Chapters 14
- rokonoid Chapters 5
- ronnyfm Chapters 1
- Salah Eddine Lahniche Chapters 3
- saml Chapters 3
- Sardathrion Chapters 22
- Sascha Chapters 5
- Sascha Wolf Chapters 5
- SashaZd Chapters 48
- Sazzad Hissain Khan Chapters 1
- Scott Weldon Chapters 3, 5, 22, 23, 41, 51
- Sebastianb Chapters 5, 26
- SeeuD1 Chapters 5
- shoelzer Chapters 46
- Shog9 Chapters 23
- Simone Carletti Chapters 14, 41
- sjas Chapters 5
- SommerEngineering Chapters 10
- sonali Chapters 45
- Sonny Kim Chapters 10
- spikeheap Chapters 5
- Stony Chapters 23
- strangeqargo Chapters 18
- SurDin Chapters 6
- Tall Sam Chapters 16
- textshell Chapters 7
- Thamilan Chapters 23
- thanksd Chapters 11
- the12 Chapters 14
- TheDarkKnight Chapters 36, 59
- theJollySin Chapters 5
- Thomas Crowley Chapters 60
- tinlyx Chapters 9
- Toby Chapters 5, 20
- Toby Allen Chapters 2
- Tom Gijselinck Chapters 5
- Tom Hale Chapters 11
- Tomás Cañibano Chapters 26, 29
- Tomasz Bąk Chapters 5
- Travis Chapters 12
- Tyler Zika Chapters 1
- tymspy Chapters 1
- Undo Chapters 8, 9, 10, 25
- Uwe Chapters 14
- Vi. Chapters 5
- Victor Schröder Chapters 5, 12, 44
- Vivin George Chapters 3
- Vlad Chapters 14
- Vladimir F Chapters 10
- Vogel612 Chapters 8
- VonC Chapters 1, 3, 5, 9, 12, 13
- Wasabi Fan Chapters 12
- Wilfred Hughes Chapters 5
- Will Chapters 6
- Wojciech Kazior Chapters 11, 25, 26
- Wolfgang Chapters 4, 5, 8, 13, 14
- WPrecht Chapters 42
- xiaoyaoworm Chapters 58
- ydaetskcoR Chapters 5
- Yerko Palma Chapters 14
- Yury Fedorov Chapters 5, 14
- Zaz Chapters 6, 7, 10, 18, 23, 37
- zebediah49 Chapters 41
- zygimantus Chapters 14
- ɴʏɪɪs Chapters 18