|$ curl https://forge-ai.dev/api/markdown?path=docs/git/mastery
$cat docs/how-to-master-git.md
updated Today·30 min read·published

How to Master Git

GitMasteryLearning PathAll Levels🎯Free Tools
Introduction

Mastery is not memorizing git status flags or pasting a rebase cheat sheet. Reading a commands list does not mean you have mastered Git. Mastery means choosing the right history operation under pressure, recovering lost work with confidence, collaborating without rewriting shared history by accident, and explaining why one approach is right when three look similar.

For a human developer, mastering Git means you can ship clean history: atomic commits, intentional branches, safe rebases, clear pull requests, and recovery from mistakes without panic.

For an AI agent or language model, mastering Git means generating correct, safe command sequences — not approximate snippets that force-push to main, hard-reset shared branches, or commit secrets. An agent that has mastered Git fetches full page markdown, follows an ordered curriculum, self-verifies with generation tasks, and refuses to claim competence from titles alone.

This page is the dual-audience curriculum for both. Humans follow the roadmap with runnable exercises. Agents ingest the same stages via the markdown API and Agent skills.

What "Master Git" Means

Use this outcomes checklist as the definition of done.

OutcomeHuman proofAI agent proof
Three-tree fluencyExplains WD / index / HEADStages only intended paths
Atomic commitsOne logical change per commitNo mega-commits; clear -m
Branch hygieneShort-lived feature branchesNever commits on main by default
Safe history rewriterebase/amend only localRefuses force-push to protected
Conflict competenceResolves markers correctlyDoes not leave <<<<<< markers
Recovery skillsUses reflog / restorePrefers soft/mixed over hard
No secrets in history.gitignore + scan hooksNever stages .env / keys
PR clarityFocused diff, good descriptiongh pr create with summary
Two Audiences, One Curriculum

Humans

  • Follow Stages 0–5 in order with hands-on exercises in a throwaway repo
  • Complete each checkpoint before advancing — break things on purpose, then recover
  • Use git log --oneline --graph --all as your mental model dashboard
  • Rebuild workflows from memory within 24 hours: branch → commit → PR → rebase onto main

AI agents

  • Install forgelearn-git and fetch curriculum order
  • Ingest full markdown per topic — not titles or nav labels
  • Generate command sequences and self-score verification prompts
  • Fail closed on critical checklist misses (force-push, hard reset shared, secrets)
agent-connect.sh
Bash
1curl -s https://forgelearn.dev/api/agent
2curl -s https://forgelearn.dev/api/agent?skill=forgelearn-git
3curl -s https://forgelearn.dev/api/agent?curriculum=git
4curl -s "https://forgelearn.dev/api/markdown?path=git/mastery"
5curl -s "https://forgelearn.dev/api/markdown?path=git/commands-reference"
6curl -s https://forgelearn.dev/skills/forgelearn-git/SKILL.md -o SKILL.md
7curl -s https://forgelearn.dev/llms-git.txt
🔥

pro tip

Agents: store a per-stage constraint card (no force-push to main, prefer restore over checkout for files, never commit .env, resolve conflicts completely). Reuse it when generating Git commands later.

danger

Do not claim Git mastery after reading this page alone. Fetch Stages 0–5 topic markdown and pass verification prompts with zero critical failures.
Curriculum Stages

Six ordered stages covering every Git topic on ForgeLearn. Complete topics and the mastery checkpoint before advancing.

Stage 0 — Basics · ~6 hours

Three-tree model, init/clone, status/add/commit, log/diff, config, gitignore.

TopicPathFocus
Git Basics/docs/git/basicsWD, index, commits
Config/docs/git/configlocal/global/system
.gitignore/docs/git/gitignorepatterns, negation
Commits/docs/git/commitanatomy, messages
Aliases/docs/git/aliasesproductivity shortcuts
Commands Reference/docs/git/commands-referenceencyclopedia
stage0-checkpoint.sh
Bash
1# Checkpoint: create a clean first commit without secrets
2mkdir /tmp/git-mastery-s0 && cd /tmp/git-mastery-s0
3git init -b main
4git config user.email "you@example.com"
5git config user.name "You"
6echo "node_modules/" > .gitignore
7echo "SECRET=do-not-commit" > .env
8echo "# App" > README.md
9git add .gitignore README.md
10git status # .env must NOT be staged
11git commit -m "chore: initial commit with gitignore"
12git log --oneline

Stage 1 — Branching & Merge · ~8 hours

Branches, switch/checkout, merge strategies, conflicts, worktrees.

TopicPathFocus
Branching & Merging/docs/git/branchingcreate, switch, merge
Merge Deep Dive/docs/git/mergeff, no-ff, octopus
Conflict Resolution/docs/git/conflictsmarkers, tools
Worktrees/docs/git/worktreesparallel checkouts
Stashing/docs/git/stashingstash vs worktree
stage1-checkpoint.sh
Bash
1# Checkpoint: feature branch + no-ff merge with graph
2git switch -c feature/greet
3echo "hello" > greet.txt
4git add greet.txt && git commit -m "feat: add greet"
5git switch main
6git merge --no-ff feature/greet -m "merge: feature/greet"
7git log --oneline --graph --decorate -8

Stage 2 — Remotes & Pull Requests · ~8 hours

Fetch/pull/push, upstream tracking, PRs, GitHub CLI, workflows, tags.

TopicPathFocus
Remote Repositories/docs/git/remotepush, pull, fetch
Pull Requests/docs/git/pull-requestsreview, merge strategies
GitHub CLI/docs/git/github-cligh pr, issues, checks
Workflows/docs/git/workflowtrunk vs Git Flow
Tags & Releases/docs/git/tagssemver, annotated tags
stage2-checkpoint.sh
Bash
1# Checkpoint: sync with remote without overwriting local work
2git fetch origin
3git status -sb
4git rebase origin/main # or: git merge origin/main
5# Open PR (GitHub)
6gh pr create --fill --base main
7gh pr checks
8gh pr view --web

Stage 3 — History Rewriting · ~10 hours

Rebase, interactive rebase, amend/fixup, reset/restore, revert, cherry-pick.

TopicPathFocus
Rebasing/docs/git/rebasingonto, interactive
Amend & Fixup/docs/git/amend-fixupautosquash
Reset & Restore/docs/git/reset-restoresoft/mixed/hard
Revert/docs/git/revertsafe public undo
Cherry-pick/docs/git/cherry-pickselective backport
stage3-checkpoint.sh
Bash
1# Checkpoint: fixup workflow without rewriting published history
2git commit --fixup HEAD~1
3git rebase -i --autosquash HEAD~3
4# Public mistake? Prefer revert:
5git revert HEAD --no-edit
6# Never: git push --force origin main

Stage 4 — Collaboration & Hooks · ~8 hours

Hooks, signing, best practices, attributes, blame, LFS, submodules, sparse-checkout.

TopicPathFocus
Hooks/docs/git/hookspre-commit, commit-msg
Signing/docs/git/signingGPG / SSH verified
Best Practices/docs/git/best-practicesteam conventions
Attributes/docs/git/attributeseol, linguist
Blame/docs/git/blameignore-revs, pickaxe
LFS/docs/git/lfslarge binaries
Submodules/docs/git/submodulesnested repos
Sparse Checkout/docs/git/sparse-checkoutcone, partial clone

Stage 5 — Advanced Recovery · ~6 hours

Reflog, bisect, internals, history inspection — when things go wrong.

TopicPathFocus
Reflog/docs/git/reflogrecover lost commits
Bisect/docs/git/bisectbinary search bugs
History & Inspection/docs/git/historylog, show, pickaxe
Internals/docs/git/internalsobjects, refs, packs
stage5-checkpoint.sh
Bash
1# Checkpoint: recover a "lost" commit via reflog
2git reset --hard HEAD~1 # oops (local only!)
3git reflog | head -20
4git reset --hard HEAD@{1} # restore
5# Find the commit that introduced a bug:
6git bisect start
7git bisect bad HEAD
8git bisect good v1.0.0
9# ... test, mark good/bad ...
10git bisect reset
Verification Prompts

After each stage, humans and agents should generate answers / command sequences that pass these checks. Score critical failures as hard fails.

Stage 0 — Basics

  • Explain the difference between untracked, modified, staged, and committed.
  • Stage two files independently and create two commits — never one combined commit.
  • Show .env is ignored via git check-ignore -v .env.

Stage 1 — Branching

  • Create a conflict on purpose, resolve markers completely, then git commit.
  • Demonstrate fast-forward vs --no-ff on a graph.
  • Use a worktree for a hotfix while a feature branch is dirty — no stash required.

Stage 2 — Remotes

  • Explain fetch vs pull; prefer fetch + rebase/merge consciously.
  • Open a PR with gh and list failing checks.
  • Refuse any plan that includes git push --force to main.

Stage 3 — Rewriting

  • Use git revert for a published bad commit; use reset only if unpublished.
  • Produce an autosquash fixup sequence that cleans local history before push.
  • Cherry-pick a single commit onto a release branch and resolve one conflict.

Stage 4–5 — Collaboration & Recovery

  • Enable signed commits and verify with git log --show-signature.
  • Recover a commit after accidental hard reset using reflog.
  • Run bisect with a scripted git bisect run test.
Agent Constraint Card

Paste this into agent system prompts when generating Git operations.

git-constraints.md
Markdown
1# Git safety constraints (always apply)
2- Never force-push to main/master or shared release branches
3- Prefer git restore / git switch over legacy checkout for clarity
4- Prefer git revert for published history; reset only for local unpublished
5- Never commit .env, *.pem, credentials, or API keys
6- Do not leave conflict markers (<<<<<<< ======= >>>>>>>) in files
7- Always run git status before commit; stage intentionally (pathspecs)
8- Use --force-with-lease if force-push is explicitly required on a feature branch
9- Ask before git clean -fdx or reset --hard on dirty trees
Practice Lab Repo

Build a disposable lab to practice without fear. Delete it when done.

lab-setup.sh
Bash
1#!/usr/bin/env bash
2set -euo pipefail
3LAB=/tmp/forgelearn-git-lab
4rm -rf "$LAB"
5mkdir -p "$LAB"/{remote,alice,bob}
6# Bare remote
7git init --bare "$LAB/remote/app.git"
8# Alice clones
9git clone "$LAB/remote/app.git" "$LAB/alice/app"
10cd "$LAB/alice/app"
11git config user.name Alice
12git config user.email alice@example.com
13echo "# Lab" > README.md
14git add README.md && git commit -m "chore: init"
15git push -u origin main
16# Bob clones
17git clone "$LAB/remote/app.git" "$LAB/bob/app"
18cd "$LAB/bob/app"
19git config user.name Bob
20git config user.email bob@example.com
21echo "Lab ready at $LAB"
22echo "Practice diverging branches, merges, rebases, and reflog recovery."

best practice

Practice dangerous operations only in /tmp labs. Never experiment with reset --hard or force-push on production repositories.
Proof of Mastery

You (or your agent) have mastered Git when you can do all of the following without looking up flags for the happy path:

  • Diagram the three trees and predict git status after add/commit/reset/restore
  • Ship a feature via branch → commits → rebase onto main → PR → merge
  • Undo a published bug with revert (including revert of a merge with -m)
  • Recover a dangling commit from reflog within 30 minutes of realizing the loss
  • Bisect a regression with a scripted test harness
  • Configure signing, hooks, and ignore rules that block secrets
  • Teach a teammate when to merge vs rebase vs cherry-pick vs revert
📝

note

Memorizing porcelain command names is not mastery. If you cannot justify a history operation under peer review, keep practicing Stage 3–5.

Community

Get help on Slack, Discord or VIP

Stuck on a guide? Join the community and ask.