Pro Git Ch1 — Getting Started
- Description: Notes on Pro Git (2nd ed.) Chapter 1 — version control concepts, Git's design (snapshot model, three states), installing Git, first-time setup, and the built-in help system.
- My Notion Note ID: K2B-2-1
- Created: 2020-06-02
- Updated: 2026-05-19
- License: Reuse is very welcome. Please credit Yu Zhang and link back to the original on yuzhang.io
Table of Contents
- 1. About Version Control
- 2. A Short History of Git
- 3. What is Git
- 4. The Command Line
- 5. Installing Git
- 6. First-Time Setup
- 7. Getting Help
- 8. References
1. About Version Control
- VCS = system that records changes to a file (or set of files) over time so you can recall specific versions later.
- Three families, in order of increasing capability:
- Local VCS — single-machine version database (e.g. RCS). Fragile if the machine dies.
- Centralized VCS (CVCS) — single server holds history; clients check out latest snapshot (SVN, CVS, Perforce). Single point of failure.
- Distributed VCS (DVCS) — every clone is a full backup with history (Git, Mercurial, Bazaar). Server is a convention, not a requirement.
2. A Short History of Git
- Linux kernel used BitKeeper (proprietary DVCS) from 2002 to 2005.
- 2005: BitKeeper free-use terms revoked → kernel community needed an alternative.
- Linus Torvalds wrote Git in ~10 days. Design goals:
- Speed.
- Simple design.
- Strong support for non-linear development (thousands of parallel branches).
- Fully distributed.
- Handle large projects (kernel-scale) efficiently.
3. What is Git
3.1 Snapshots, not differences
- Each commit stores a reference to a snapshot of the entire tree at that point.
- Unchanged files = pointer to the previous identical blob (no duplication).
- This is fundamentally different from delta-based systems (SVN, CVS) that store per-file change history.
3.2 Nearly every operation is local
- Full history lives in
.git/on your machine. log,diff,commit,branch,mergeall work offline.- Network only needed for
fetch,pull,push,clone.
3.3 Integrity via SHA-1
- Every object is content-addressed by a 40-hex-character SHA-1 hash.
- Cannot change a file or commit without Git knowing — the hash changes.
- (Git is migrating toward SHA-256 as an opt-in object format; SHA-1 is still the default.)
3.4 Only adds data
- Once committed, data is hard to lose — recoverable via
reflogand dangling objects for ~90 days (default). - The
git rm/git reset --hardetc. don't delete history; they move pointers.
3.5 Three states / three areas
| State | Where | Meaning |
|---|---|---|
| Modified | Working tree | Edited but not yet staged. |
| Staged | Index (.git/index) |
Marked for inclusion in the next commit. |
| Committed | Repo (.git/) |
Snapshot stored in the object database. |
Basic workflow: edit → git add → git commit.
4. The Command Line
- Pro Git assumes CLI — the only interface where all commands are available.
- GUI tools (GitHub Desktop, Tower, SourceTree, GitKraken) implement a subset, often missing advanced operations.
- macOS / Linux: built-in terminal. Windows: Git Bash (ships with Git for Windows) or PowerShell.
5. Installing Git
# Linux
sudo apt install git-all # Debian/Ubuntu
sudo dnf install git-all # Fedora/RHEL
# macOS
brew install git # Homebrew
git --version # triggers Xcode CLI tools install on first run
# Windows
# Download installer from https://git-scm.com (includes Git Bash)
# Verify
git --version
Building from source gives the most up-to-date version; needs gcc, openssl, curl, expat, gettext, zlib.
6. First-Time Setup
6.1 Config scopes
Three levels, lowest wins on read:
| File | Flag | Scope |
|---|---|---|
/etc/gitconfig |
--system |
All users on this machine. |
~/.gitconfig or ~/.config/git/config |
--global |
Current user. |
<repo>/.git/config |
--local (default) |
Single repo. |
6.2 Required identity
git config --global user.name "Yu Zhang"
git config --global user.email "[email protected]"
6.3 Common extras
git config --global core.editor vim
git config --global init.defaultBranch main # Git 2.28+
git config --global pull.rebase true # rebase on pull instead of merge
git config --global credential.helper cache # short-term username/password cache
6.4 Inspect
git config --list # all sources merged
git config --list --show-origin # which file each setting came from
git config user.name # single key
7. Getting Help
Three equivalent forms for the full manual:
git help <command>
git <command> --help
man git-<command>
Other:
git <command> -h— short usage summary.git help <concept>— concept guides (e.g.git help everyday,git help workflows,git help glossary).git help -g— list all installed guides.