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.

Tutorial·Difficulty: Intermediate·12 chapters·Updated Apr 19, 2026

Chapters

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 git commands and start understanding what they do

Contents

Fundamentals

  1. Introduction: What git is, the commit graph, install, your first repository
  2. Basics: add, commit, status, diff, log, and the staging area

Core Concepts

  1. Branches: branch, switch, merge (fast-forward and three-way)
  2. Remotes: remote, fetch, pull, push, tracking branches
  3. History: log options, show, blame, bisect, searching commits

Advanced

  1. Rebase: rebase, interactive rebase, squashing, reordering
  2. Conflicts: merge and rebase conflicts, resolution, rerere
  3. Rewriting History: amend, reset, revert, reflog, recovery
  4. Internals: objects (blob, tree, commit, tag), refs, the .git directory

Ecosystem

  1. Workflows: trunk-based, git flow, PRs, feature branches
  2. Tooling: hooks, submodules, worktrees, aliases, configuration, LFS

Mastery

  1. Best Practices: commit messages, branching conventions, recovery patterns, anti-patterns

How to Use This Tutorial

  1. Read sequentially for a complete learning path
  2. Type out the commands. Don't just read them
  3. 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)

  1. Chapters 01 to 05 for the flow you use every day
  2. Chapter 08 for undo and recovery
  3. Chapter 12 for conventions

Getting good at rebase (roughly 3 hours)

  1. Chapter 06 for rebase, 07 for conflicts
  2. Chapter 08 for the safety net (reflog, reset)

Understanding git (roughly 4 hours)

  1. Chapter 09 for internals
  2. Chapter 08 to see how the commands map to object manipulation
  3. Chapter 06 with the internals in mind

Additional Resources

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+.