Git tutorial
Learn how to track code changes and work safely with other developers.
Course contents
Orientation
- Git Basics — What Git does, the chain of snapshots behind it, your first repository and first commit, how commits are named, and how to tell Git who you are.
Daily Work
- Ignoring Files — What .gitignore does, how to write the patterns, why ignoring a file you already committed changes nothing, and how to stop tracking one without deleting it.
- Daily Workflow — The loop you live in: reading git status, what git add really records, the ways to stage, recording deletions, committing well, and amending the last commit.
- Reviewing Changes — Reading what you changed before you commit it, comparing branches and commits, walking the history with log, and opening a single commit with show.
- Undoing Changes — The two kinds of undo before a commit: unstaging safely, discarding permanently, restoring a file from an older commit, undoing a staged deletion, and cleaning untracked files.
Branching and Merging
- Branches — What a branch really is, creating and switching and deleting them, what switching does to your files, detached HEAD, and the feature-branch habit teams rely on.
- Moving Changes — Parking uncommitted work with stash, managing the stash list, copying a single commit with cherry-pick, and resolving a conflict in the middle of one.
- Merging Changes — Fast-forward versus a real merge commit, how three-way merging decides, resolving a conflict from start to finish, aborting safely, and shaping history with --no-ff and --squash.
Working with Others
- Hosting Platforms — Where Git stops and GitHub or GitLab begins: the vocabulary side by side, the merge buttons translated, the settings worth turning on, and what does and does not move between hosts.
- Remote Repos — The three kinds of branch, what ahead and behind and diverged mean, cloning, managing remotes, why fetch is safe when pull is not, rejected pushes, and upstream tracking.
- Collaboration Workflows — The six-step loop a team runs, keeping a branch current, the three ways a branch lands, why a squashed branch looks unmerged, force-pushing safely, and protected branches.
- Rewriting History — What rebase does to your commits and why their hashes change, when it is safe, resolving conflicts mid-replay, interactive rebase, and moving a branch with --onto.
When Things Go Wrong
- Fixing Mistakes — Choosing between amend, reset and revert, the three reset modes and what each one keeps, undoing a shared commit safely, and when rewriting history is allowed.
- Recovering Work — What the reflog records, why lost commits are usually still there, recovering from a bad reset or a deleted branch or an unwanted rebase, and the limits of reflog recovery.
- History Investigation — Reading the shape of a repository's history, narrowing to one file, finding when a line of code appeared with the pickaxe, using blame, and bisecting to the exact bad commit.
Deeper
- Git Foundations — Why commits are snapshots rather than diffs, the four object types and how they chain together, content-addressed hashing, the three trees, HEAD and branches, and why ignore rules cannot reach a tracked file.
- Releases & Tags — Lightweight versus annotated tags, generating version strings with git describe, why tags are not pushed with your commits, and what signing adds to a release.
- Branch Strategies — Choosing between GitHub Flow, Git Flow and trunk-based development, running the full Git Flow lifecycle, generating versions from history, and branch naming conventions.
- Git Customization — The three configuration levels and which wins, the settings worth turning on once, aliases, keeping work and personal identities apart, and why hooks are a convenience rather than a control.
- Advanced Repositories — Several checkouts sharing one object store, what worktrees share and keep separate, and submodules: what the gitlink records, how updates work, and when a package is the better answer.
- AI Workflows — Using Git when an agent writes the code: checkpoints before a run, one branch per task, a worktree per simultaneous agent, commit hygiene that allows partial rejection, and reviewing work you did not write.
- Large Repositories — Telling the three kinds of too-big apart, shallow clones for CI, sparse checkout for monorepos, partial clones that fetch contents on demand, Git LFS for binaries, and repository maintenance.
- Git Internals — Inside the .git directory, how an object's name is computed from its type and contents, what trees store beyond names, why renames are inferred, and the plumbing commands that never lie.
Reference
- Error Guide — The Git messages you will actually meet, decoded: what fatal, error, warning and hint each mean, the families they fall into, and the four commands that answer almost any of them.
- Git Cheat Sheet — Every command on this course in one place, grouped by the job you are doing: starting out, the daily loop, branching, remotes, undoing, moving work, investigating, plumbing, settings, and the destructive ones.