Tutorial
Git Tutorial
A practical tutorial on Git, from your first commit to rebasing, recovery, and everyday team workflows. Covers the commit graph, branching, remotes, history rewriting, internals, workflows, and the conventions that keep a repo healthy.
Chapters
01
Introduction: What Git Actually Is
02
Basics: The Daily Loop
03
Branches: Parallel Lines of Work
04
Remotes: Off Your Laptop
05
History: Reading the Past
06
Rebase: Reshaping History
07
Conflicts: When Git Stops and Asks
08
Rewriting History: Amend, Reset, Revert, Reflog
09
Internals: It's Just Files
10
Workflows: How Teams Actually Use Git
11
Tooling: Hooks, Submodules, Worktrees, and Friends
12
Best Practices: Habits That Keep a Repo Healthy
About this tutorial
A practical tour of Git, from your first commit to the commands you reach for when something has gone sideways.
Who This Is For
- Developers who use Git daily but want a mental model stronger than "git push, hope for the best"
- Engineers who have lost work to a bad merge or rebase and want to know how to recover
- Anyone ready to stop copy-pasting
gitcommands and start understanding what they do
Contents
Fundamentals
- Introduction: What git is, the commit graph, install, your first repository
- Basics: add, commit, status, diff, log, and the staging area
Core Concepts
- Branches: branch, switch, merge (fast-forward and three-way)
- Remotes: remote, fetch, pull, push, tracking branches
- History: log options, show, blame, bisect, searching commits
Advanced
- Rebase: rebase, interactive rebase, squashing, reordering
- Conflicts: merge and rebase conflicts, resolution, rerere
- Rewriting History: amend, reset, revert, reflog, recovery
- Internals: objects (blob, tree, commit, tag), refs, the .git directory
Ecosystem
- Workflows: trunk-based, git flow, PRs, feature branches
- Tooling: hooks, submodules, worktrees, aliases, configuration, LFS
Mastery
- Best Practices: commit messages, branching conventions, recovery patterns, anti-patterns
How to Use This Tutorial
- Read sequentially for a complete learning path
- Type out the commands. Don't just read them
- Have a throwaway repo open. Break it on purpose. The reflog has your back
Quick Reference
Essential Commands
# Start or join a repo
git init
git clone git@github.com:user/repo.git
# The daily loop
git status
git add path/to/file
git commit -m "short message"
git log --oneline --graph
# Move between branches
git switch main
git switch -c feature/new-thing
# Sync with a remote
git fetch
git pull --rebase
git push
# Undo things
git restore path/to/file # discard unstaged changes
git restore --staged path/to/file # unstage
git reset --soft HEAD~1 # undo last commit, keep changes staged
git revert <sha> # new commit that undoes another
git reflog # the safety net
Your First Repository
mkdir notes && cd notes
git init
echo "# Notes" > README.md
git add README.md
git commit -m "first commit"
git log
Common Patterns
# Rebase a feature branch onto the latest main
git switch feature/login
git fetch origin
git rebase origin/main
# Squash the last three commits
git rebase -i HEAD~3
# Amend the last commit (message or files)
git commit --amend
# Recover a branch you thought you lost
git reflog
git switch -c rescued <sha-from-reflog>
# Pull latest and rebase your local work on top
git pull --rebase
Learning Path Suggestions
Day-to-day fluency (roughly 6 hours)
- Chapters 01 to 05 for the flow you use every day
- Chapter 08 for undo and recovery
- Chapter 12 for conventions
Getting good at rebase (roughly 3 hours)
- Chapter 06 for rebase, 07 for conflicts
- Chapter 08 for the safety net (reflog, reset)
Understanding git (roughly 4 hours)
- Chapter 09 for internals
- Chapter 08 to see how the commands map to object manipulation
- Chapter 06 with the internals in mind
Additional Resources
- Pro Git book (free, definitive)
- Git official docs
- Oh My Git! (interactive game for the commit graph)
- Learn Git Branching (visual exercises)
- Dangit, Git!?! (recipes for "I broke it")
Git Version
This tutorial is written for Git 2.40+ and uses modern commands (switch, restore) where older material might use checkout. Most examples work on Git 2.23+.