Table of Contents
License
Preface by Scott Chacon
Preface by Ben Straub
Dedications
Contributors
Introduction
Getting Started
About Version Control
Local Version Control Systems
Centralized Version Control Systems
Distributed Version Control Systems
A Short History of Git
What is Git?
Snapshots, Not Differences
Nearly Every Operation Is Local
Git Has Integrity
Git Generally Only Adds Data
The Three States
The Command Line
Installing Git
Installing on Linux
Installing on macOS
Installing on Windows
Installing from Source
First-Time Git Setup
Your Identity
Your Editor
Your default branch name
Checking Your Settings
Getting Help
Summary
Git Basics
Getting a Git Repository
Initializing a Repository in an Existing Directory
Cloning an Existing Repository
Recording Changes to the Repository
Checking the Status of Your Files
Tracking New Files
Staging Modified Files
Short Status
Ignoring Files
Viewing Your Staged and Unstaged Changes
Committing Your Changes
Skipping the Staging Area
Removing Files
Moving Files
Viewing the Commit History
Limiting Log Output
Undoing Things
Unstaging a Staged File
Unmodifying a Modified File
Undoing things with git restore
Working with Remotes
Showing Your Remotes
Adding Remote Repositories
Fetching and Pulling from Your Remotes
Pushing to Your Remotes
Inspecting a Remote
Renaming and Removing Remotes
Tagging
Listing Your Tags
Creating Tags
Annotated Tags
Lightweight Tags
Tagging Later
Sharing Tags
Deleting Tags
Checking out Tags
Git Aliases
Summary
Git Branching
Branches in a Nutshell
Creating a New Branch
Switching Branches
Basic Branching and Merging
Basic Branching
Basic Merging
Basic Merge Conflicts
Branch Management
Changing a branch name
Branching Workflows
Long-Running Branches
Topic Branches
Remote Branches
Pushing
Tracking Branches
Pulling
Deleting Remote Branches
Rebasing
The Basic Rebase
More Interesting Rebases
The Perils of Rebasing
Rebase When You Rebase
Rebase vs. Merge
Summary
Git on the Server
The Protocols
Local Protocol
The HTTP Protocols
The SSH Protocol
The Git Protocol
Getting Git on a Server
Putting the Bare Repository on a Server
Small Setups
Generating Your SSH Public Key
Setting Up the Server
Git Daemon
Smart HTTP
GitWeb
GitLab
Installation
Administration
Basic Usage
Working Together
Third Party Hosted Options
Summary
Distributed Git
Distributed Workflows
Centralized Workflow
Integration-Manager Workflow
Dictator and Lieutenants Workflow
Patterns for Managing Source Code Branches
Workflows Summary
Contributing to a Project
Commit Guidelines
Private Small Team
Private Managed Team
Forked Public Project
Public Project over Email
Summary
Maintaining a Project
Working in Topic Branches
Applying Patches from Email
Checking Out Remote Branches
Determining What Is Introduced
Integrating Contributed Work
Tagging Your Releases
Generating a Build Number
Preparing a Release
The Shortlog
Summary
GitHub
Account Setup and Configuration
SSH Access
Your Avatar
Your Email Addresses
Two Factor Authentication
Contributing to a Project
Forking Projects
The GitHub Flow
Advanced Pull Requests
GitHub Flavored Markdown
Keep your GitHub public repository up-to-date
Maintaining a Project
Creating a New Repository
Adding Collaborators
Managing Pull Requests
Mentions and Notifications
Special Files
README
CONTRIBUTING
Project Administration
Managing an organization
Organization Basics
Teams
Audit Log
Scripting GitHub
Services and Hooks
The GitHub API
Basic Usage
Commenting on an Issue
Changing the Status of a Pull Request
Octokit
Summary
Git Tools
Revision Selection
Single Revisions
Short SHA-1
Branch References
RefLog Shortnames
Ancestry References
Commit Ranges
Interactive Staging
Staging and Unstaging Files
Staging Patches
Stashing and Cleaning
Stashing Your Work
Creative Stashing
Creating a Branch from a Stash
Cleaning your Working Directory
Signing Your Work
GPG Introduction
Signing Tags
Verifying Tags
Signing Commits
Everyone Must Sign
Searching
Git Grep
Git Log Searching
Rewriting History
Changing the Last Commit
Changing Multiple Commit Messages
Reordering Commits
Squashing Commits
Splitting a Commit
Deleting a commit
The Nuclear Option: filter-branch
Reset Demystified
The Three Trees
The Workflow
The Role of Reset
Reset With a Path
Squashing
Check It Out
Summary
Advanced Merging
Merge Conflicts
Undoing Merges
Other Types of Merges
Rerere
Debugging with Git
File Annotation
Binary Search
Submodules
Starting with Submodules
Cloning a Project with Submodules
Working on a Project with Submodules
Submodule Tips
Issues with Submodules
Bundling
Replace
Credential Storage
Under the Hood
A Custom Credential Cache
Summary
Customizing Git
Git Configuration
Basic Client Configuration
Colors in Git
External Merge and Diff Tools
Formatting and Whitespace
Server Configuration
Git Attributes
Binary Files
Keyword Expansion
Exporting Your Repository
Merge Strategies
Git Hooks
Installing a Hook
Client-Side Hooks
Server-Side Hooks
An Example Git-Enforced Policy
Server-Side Hook
Client-Side Hooks
Summary
Git and Other Systems
Git as a Client
Git and Subversion
Git and Mercurial
Git and Perforce
Migrating to Git
Subversion
Mercurial
Perforce
A Custom Importer
Summary
Git Internals
Plumbing and Porcelain
Git Objects
Tree Objects
Commit Objects
Object Storage
Git References
The HEAD
Tags
Remotes
Packfiles
The Refspec
Pushing Refspecs
Deleting References
Transfer Protocols
The Dumb Protocol
The Smart Protocol
Protocols Summary
Maintenance and Data Recovery
Maintenance
Data Recovery
Removing Objects
Environment Variables
Global Behavior
Repository Locations
Pathspecs
Committing
Networking
Diffing and Merging
Debugging
Miscellaneous
Summary
Appendix A: Git in Other Environments
Graphical Interfaces
gitk
and
git-gui
GitHub for macOS and Windows
Other GUIs
Git in Visual Studio
Git in Visual Studio Code
Git in IntelliJ / PyCharm / WebStorm / PhpStorm / RubyMine
Git in Sublime Text
Git in Bash
Git in Zsh
Git in PowerShell
Installation
Summary
Appendix B: Embedding Git in your Applications
Command-line Git
Libgit2
Advanced Functionality
Other Bindings
Further Reading
JGit
Getting Set Up
Plumbing
Porcelain
Further Reading
go-git
Advanced Functionality
Further Reading
Dulwich
Further Reading
Appendix C: Git Commands
Setup and Config
git config
git config core.editor commands
git help
Getting and Creating Projects
git init
git clone
Basic Snapshotting
git add
git status
git diff
git difftool
git commit
git reset
git rm
git mv
git clean
Branching and Merging
git branch
git checkout
git merge
git mergetool
git log
git stash
git tag
Sharing and Updating Projects
git fetch
git pull
git push
git remote
git archive
git submodule
Inspection and Comparison
git show
git shortlog
git describe
Debugging
git bisect
git blame
git grep
Patching
git cherry-pick
git rebase
git revert
Email
git apply
git am
git format-patch
git imap-send
git send-email
git request-pull
External Systems
git svn
git fast-import
Administration
git gc
git fsck
git reflog
git filter-branch
Plumbing Commands