Git Reference
Essential Git commands, workflows, and cheat sheets for developers.
Git is a distributed version control system that tracks changes to files over time. It lets multiple developers collaborate on the same codebase, maintain a full history of every change, and safely experiment with new ideas using branches.
Every Git project has a .git/ directory that stores the entire history. You work in the working tree, stage changes to the index, and permanently record them as commits.
Core Workflow
The everyday Git cycle: modify files → stage changes → commit.
bash
# 1. Check what changed
git status
# 2. Stage specific files (or use . for all)
git add src/feature.ts
# 3. Commit with a clear message
git commit -m "feat: add user authentication"
# 4. Push to remote
git pushGit Chapters
The Three Areas
Working Tree
Your actual files on disk. Edits here are untracked until staged.
git statusStaging Area (Index)
A snapshot of what will go into the next commit. Populated with git add.
git add <file>Repository (.git)
Permanent commit history. Immutable once committed.
git commitFirst-Time Setup
Before using Git, configure your identity. These values are stored in every commit you make.
bash
git config --global user.name "Your Name"
git config --global user.email "[email protected]"
# Set default branch name to main
git config --global init.defaultBranch main
# Set preferred editor
git config --global core.editor "code --wait"
# Verify configuration
git config --list