A practical model of commits, branch pointers, staging, merges, rebases, pull requests, and conflicts without the hand-waving.
What this deck does
Start with the actual data model, then follow one change from your working tree to a reviewed merge.
flowchart LR
WD["Working Directory"] -->|git add| SA["Staging Area"]
SA -->|git commit| REPO["Repository (.git/)"]
WD --- M["Modified"]
SA --- S["Staged"]
REPO --- C["Committed"]Distributed version control
The atomic unit
commit a1b2c3d4e5f6...
Author: you <you@email.com>
Date: Mon Mar 24 2026
Add login page
parent: f9e8d7c6...
tree: 3a4b5c6d...
Every commit gets a SHA hash. Change anything about that commit and the hash changes too. That is how Git keeps the history tamper-evident.
Daily workflow
git status
git add index.html
git add .
git commit -m "Add login page"
git log --oneline
Going back in time
git reset --soft HEAD~1
git reset --hard HEAD~1
git revert a1b2c3d
Ignoring files
Use a root .gitignore early so build artifacts, logs, temp files, and generated output do not show up as untracked noise or get committed by accident.
# object and archive files
*.[oa]
# editor backup files
*~
# ignore all build directories
build/
# ignore generated PDFs under doc/
doc/**/*.pdf
# keep one specific archive even though *.a is ignored
!lib.a# are ignored./ to anchor to the current directory, end with / to target a directory.! to negate a match and keep a file tracked.
* matches many characters, ? matches one, [0-9] matches a range, and ** can match nested directories like doc/**/*.pdf.
If you need a starting point for a language or framework, GitHub’s github/gitignore repository has maintained examples.
flowchart LR
A["main: A"] --> B["B"]
B --> C["C"]
C --> G["G merge"]
C --> D["D"]
D --> E["E"]
E --> F["F"]
F --> G
What a branch really is
git branch
git switch -c add-login
git switch main
git merge add-login
git branch -d add-login
Merge
A ── B ── C ── G
\ /
D─E─F
Merge preserves the branching history. If both sides moved, Git may create a merge commit that shows exactly where they came back together.
Rebase
git switch add-login
git rebase main
# Before: C -> D -> E -> F
# After: C -> D' -> E' -> F'
Rebase rewrites history to make it linear. Never rebase a branch other people are already using.
Pull requests
On a team, the branch becomes public first. Then review, discussion, and CI checks happen before the merge.
Branch → commit → push → review → merge
`git switch -c feat/user-auth`
Record work in small snapshots.
`git push -u origin feat/user-auth`
Create the PR in GitHub or GitLab.
Comments and checks happen on the branch.
Merge, then delete the branch.
Conflict markers
function getColor() {
<<<<<<< HEAD
return "red";
=======
return "blue";
>>>>>>> alex/feature-colors
}
git status
# edit the file and remove markers
git add utils.js
git commit -m "Resolve merge conflict in getColor()"
Git can auto-merge most changes. A conflict only happens when both branches changed the same lines differently.
Avoiding conflicts
git fetch origin
git rebase origin/main
# or:
git merge origin/main
The longer your branch lives without syncing, the more it diverges and the uglier the conflict gets.
Mental model summary
Once that clicks, the commands stop feeling random.
| Concept | What it actually is |
|---|---|
| Repository | A folder plus .git/ storing the full history |
| Commit | A snapshot with a SHA, author, message, and parent pointer |
| Branch | A lightweight pointer to a commit |
| HEAD | A pointer to your current place in history |
| Merge | Combining two branch histories |
| Rebase | Replaying commits on top of another branch |
| Pull Request | A structured request to review and merge a branch |
| Merge Conflict | Two branches changed the same lines differently |
The mental model should stay in your head. The commands can live in the docs.
Interactive deep dive
Walk through repositories, staging, commits, branches, pull requests, and conflicts one concept at a time.
Open /git-explainerCommand reference
Use the cheat sheet when you understand the operation but need the exact command shape fast.
git-scm.com/cheat-sheetSource background for this deck: Pro Git chapters 1–3.