Foreword xv
About the Author xvii
About the Technical Reviewer xviii
Acknowledgments xix
Introduction xxi
Chapter 1 Getting Started 1
About Version Control 1
Local Version Control Systems 2
Centralized Version Control Systems 3
Distributed Version Control Systems 4
A Short History of Git 5
Git Basics 5
Snapshots, Not Differences 6
Nearly Every Operation Is Local 7
Git Has Integrity 7
Git Generally Only Adds Data 7
The Three States 8
Installing Git 9
Installing from Source 9
Installing on Linux 10
Installing on Mac 10
Installing on Windows 11
First-Time Git Setup 11
Your Identity 11
Your Editor 12
Your Diff Tool 12
Checking Your Settings 12
Getting Help 13
Summary 13
Chapter 2 Git Basics 15
Getting a Git Repository 15
Initializing a Repository in an Existing Directory 15
Cloning an Existing Repository 16
Recording Changes to the Repository 16
Checking the Status of Your Files 17
Tracking New Files 18
Staging Modified Files 18
Ignoring Files 20
Viewing Your Staged and Unstaged Changes 20
Committing Your Changes 23
Skipping the Staging Area 24
Removing Files 24
Moving Files 25
Viewing the Commit History 26
Limiting Log Output 30
Using a GUI to Visualize History 31
Undoing Things 32
Changing Your Last Commit 32
Unstaging a Staged File 33
Unmodifying a Modified File 34
Working with Remotes 35
Showing Your Remotes 35
Adding Remote Repositories 36
Fetching and Pulling from Your Remotes 36
Pushing to Your Remotes 37
Inspecting a Remote 37
Removing and Renaming Remotes 38
Tagging 38
Listing Your Tags 39
Creating Tags 39
Verifying Tags 41
Tagging Later 42
Sharing Tags43
Tips and Tricks 43
Auto-Completion 43
Git Aliases 44
Summary 45
Chapter 3 Git Branching 47
What a Branch Is 47
Basic Branching and Merging 53
Basic Branching 53
Basic Merging 57
Basic Merge Conflicts 58
Branch Management 60
Branching Workflows 61
Long-Running Branches 62
Topic Branches 63
Remote Branches 64
Pushing 68
Tracking Branches 69
Deleting Remote Branches 69
Rebasing 70
The Basic Rebase 70
More Interesting Rebases 72
The Perils of Rebasing 74
Summary 77
Chapter 4 Git on the Server 79
The Protocols 79
Local Protocol 80
The SSH Protocol 81
The Git Protocol 81
The HTTP/S Protocol 82
Getting Git on a Server 83
Putting the Bare Repository on a Server 84
Small Setups 85
SSH Access 85
Generating Your SSH Public Key 85
Setting Up the Server 86
Public Access 88
GitWeb 90
Gitosis 91
Git Daemon 95
Hosted Git 96
GitHub 97
Setting Up a User Account 97
Creating a New Repository 99
Importing from Subversion 101
Adding Collaborators 102
Your Project 103
Forking Projects 104
GitHub Summary 105
Summary 105
Chapter 5 Distributed Git 107
Distributed Workflows 107
Centralized Workflow 107
Integration-Manager Workflow 108
Dictator and Lieutenants Workflow 109
Contributing to a Project 110
Commit Guidelines 111
Private Small Team 112
Private Managed Team 118
Public Small Project 124
Public Large Project 127
Summary 129
Maintaining a Project 130
Working in Topic Branches 130
Applying Patches from E-mail 130
Checking Out Remote Branches 133
Determining What Is Introduced 134
Integrating Contributed Work 135
Tagging Your Releases 140
Generating a Build Number 141
Preparing a Release 141
The Shortlog 142
Summary 142
Chapter 6 Git Tools 143
Revision Selection 143
Single Revisions 143
Commit Ranges 147
Interactive Staging 150
Stashing 153
Stashing Your Work 154
Creating a Branch from a Stash 156
Rewriting History 156
Changing the Last Commit 156
Changing Multiple Commit Messages 157
Reordering Commits 158
Squashing a Commit 159
Splitting a Commit 160
The Nuclear Option: filter-branch 160
Debugging with Git 162
File Annotation 162
Binary Search 163
Submodules 165
Starting with Submodules 165
Cloning a Project with Submodules 167
Superprojects 169
Issues with Submodules 169
Subtree Merging 171
Summary 173
Chapter 7 Customizing Git 175
Git Configuration 175
Basic Client Configuration 176
Colors in Git 178
External Merge and Diff Tools 179
Formatting and Whitespace 181
Server Configuration 183
Git Attributes 184
Binary Files 184
Keyword Expansion 186
Exporting Your Repository 189
Merge Strategies 190
Git Hooks 190
Installing a Hook 190
Client-Side Hooks 191
Server-Side Hooks 192
An Example Git-Enforced Policy 193
Server-Side Hook 193
Client-Side Hooks 199
Summary 202
Chapter 8 Git and Other Systems 203
Git and Subversion 203
git svn 203
Setting Up 204
Getting Started 204
Committing Back to Subversion 206
Pulling in New Changes 207
Git Branching Issues 208
Subversion Branching 209
Subversion Commands 210
Git-Svn Summary 212
Migrating to Git 212
Importing 213
Perforce 214
A Custom Importer 216
Summary 221
Chapter 9 Git Internals 223
Plumbing and Porcelain 223
Git Objects 224
Tree Objects 226
Commit Objects 228
Object Storage 231
Git References 232
The HEAD 233
Tags 234
Remotes 235
Packfiles 235
The Refspec 238
Pushing Refspecs 239
Deleting References 240
Transfer Protocols 240
The Dumb Protocol 240
The Smart Protocol 242
Downloading Data 243
Maintenance and Data Recovery 244
Maintenance 244
Data Recovery 245
Removing Objects 247
Summary 250
Appendix Creative Commons Legal Code 251
Index 259