Skip to content
Tutorials Center
My learning

Topics

Git Tutorial

Learn Git from your first commit to branching, rebasing, remotes, internals and team workflows. 78 lessons with real commands that run in your browser, quizzes and projects.

Start learning →

of lessons completed

Getting Started

  1. 1 Getting Started with Git Learn what version control is, why Git won, how Git differs from GitHub, and run your first real Git repository right here in your browser with Git 2.56.
  2. 2 How Git Works: Snapshots and the Three Areas Understand Git's mental model - the working tree, the staging area and the repository, commits as snapshots, branches as pointers - with real commands you can run.
  3. 3 Installing and Configuring Git Install Git on Windows, macOS and Linux, then configure your identity, default branch, editor and line endings. Learn system, global and local config levels with real output.
  4. 4 Your First Repository Create a Git repository from scratch with git init, track files with git add, record commits with git commit and read history with git log. Includes a tour of the .git folder.
  5. 5 Getting Help and Learning Git Learn to find answers inside Git itself - git help, -h usage lines, command lists, a glossary of core terms, and how to read the most common Git error messages.
  6. 6 Git vs Subversion, Mercurial and Perforce Compare Git with Subversion, Mercurial and Perforce: central versus distributed design, branching, binaries and scale, plus how to migrate a repository to Git.
  7. 7 Git GUIs and IDE Integrations Tour the graphical and terminal-UI Git clients - gitk, git gui, VS Code, JetBrains IDEs and lazygit - and learn what they run underneath, so you can mix them with the CLI.

The Basic Workflow

  1. 8 Status, Diff and Seeing Changes Master git status (long, short, branch info) and git diff (working tree, staged, HEAD, stat, word diff, whitespace options) and learn to read unified diffs fluently.
  2. 9 Staging Changes: add, patch Mode and Partial Commits Learn how the Git staging area works: git add variants, git add -p for partial commits, unstaging with restore, intent-to-add and the three versions of a file.
  3. 10 Making Good Commits Learn what a Git commit really is, how to use git commit, -a, --amend and --allow-empty, and how to write atomic commits with clear, conventional messages.
  4. 11 Viewing History: log, show and Formatting Master git log and git show: oneline and graph views, filtering by author, date, message and path, custom pretty formats, and ranges like HEAD~2..HEAD.
  5. 12 .gitignore and Untracked Files Learn .gitignore patterns, negation and directory rules, global ignore files, git check-ignore, how to stop tracking a file, and how git clean removes untracked files safely.
  6. 13 Undoing Things: restore, reset and revert Basics How to undo anything in Git: discard changes with restore, unstage files, move back with reset --soft, --mixed and --hard, and undo published commits with revert.
  7. 14 Moving, Renaming and Removing Files Learn git rm, git mv and rename detection: delete tracked files, keep them on disk with --cached, rename safely, handle case-only renames and follow history.
  8. 15 git clean in Depth Learn git clean: dry runs with -n, removing untracked files and directories, ignored files with -x and -X, interactive mode, pathspecs and the safety net you do not have.

Branching and Merging

  1. 16 Branches Understand Git branches as movable pointers: create, list, switch, rename and delete them, learn what HEAD and a detached HEAD are, and name branches well.
  2. 17 Merging Branches Learn how git merge combines branches: fast-forward and three-way merges, merge commits, --no-ff, --squash, --ff-only, merge strategies and the graph shapes they make.
  3. 18 Resolving Merge Conflicts Learn why Git merge conflicts happen, how to read conflict markers, resolve them by hand, with --ours and --theirs, abort a merge, and reuse fixes with rerere.
  4. 19 Branch Management and Cleanup Manage Git branches over time: list merged and unmerged branches, delete them safely, set up tracking branches, prune stale remote branches and keep a tidy repository.
  5. 20 Tags and Releases Learn Git tags: lightweight vs annotated, tagging old commits, listing and sorting versions, pushing tags, semantic versioning, release notes with git log and git describe.
  6. 21 Stashing Work in Progress Learn git stash: shelve uncommitted changes, include untracked files, stash parts with -p, apply or pop, handle conflicts, see how stashes are stored and when to use alternatives.
  7. 22 Cherry-Pick and Applying Commits Learn git cherry-pick: copy single commits or ranges to another branch, backport fixes with -x, stage without committing, resolve conflicts and avoid duplicates.
  8. 23 Merge Strategies and Custom Merge Drivers Go beyond the default git merge: ort options, octopus merges, the subtree strategy, the built-in union driver and your own custom merge drivers for special files.

Inspecting History

  1. 24 Revision Syntax: Naming Commits Master Git revision syntax: HEAD~2 vs HEAD^2, @{n}, @{upstream}, :/text, rev:path, A..B vs A...B ranges, rev-parse and rev-list, with runnable examples.
  2. 25 Comparing Commits, Branches and Files Compare anything in Git: git diff between commits and branches, two-dot vs three-dot, range-diff, diff --stat, show rev:path, --check and diff algorithms.
  3. 26 blame, grep and Searching History Find who changed a line and why: git blame with -L, -w and -C, ignoring format commits, pickaxe search log -S and -G, git log --follow and git grep, with real output.
  4. 27 Finding Bugs with git bisect Use git bisect to find the exact commit that introduced a bug by binary search: manual good/bad marking, automated bisect run, skip, terms, log and replay.
  5. 28 The Reflog and Recovering Lost Work Use git reflog to recover commits after reset --hard, deleted branches and bad rebases. Learn HEAD@{n}, per-branch reflogs, expiry, fsck and what Git can lose.

Rewriting History

  1. 29 git reset in Depth Understand git reset through the three trees: what --soft, --mixed and --hard move, how reset differs from checkout and restore, resetting paths, ORIG_HEAD and hard reset dangers.
  2. 30 Rebasing Learn git rebase step by step: replay commits onto a new base, compare it with merge, use --onto, resolve conflicts, pull --rebase, autosquash and follow the golden rule.
  3. 31 Interactive Rebase Master git rebase -i: pick, reword, edit, squash, fixup, drop and exec, reorder commits, script the todo list with GIT_SEQUENCE_EDITOR and clean up a branch before review.
  4. 32 Amending, Splitting and Rewriting Commits Fix your last commit with --amend, split a commit in two, change authors and dates, remove a file or secret from all history and learn why force-with-lease beats force.
  5. 33 Reverting Commits Safely Use git revert to undo a commit without rewriting history: single and multiple commits, merge commits with -m, reverting a revert, conflicts, and revert versus reset.

Remotes and Collaboration

  1. 34 Remotes: clone, remote, fetch Learn what a Git remote is: clone a repository, create bare repos, manage origin with git remote, understand remote-tracking branches and the difference between fetch and pull.
  2. 35 push, pull and Tracking Branches Learn git push and git pull in depth: upstream tracking, rejected pushes, divergent branches, merge versus rebase pulls, --force-with-lease, tags and push.default.
  3. 36 Collaboration Workflows Compare GitHub flow, Gitflow, trunk-based development and the forking workflow, simulate two developers with two clones, and learn how to choose a workflow for your team.
  4. 37 Pull Requests and Code Review Understand what a pull request really is, keep a branch up to date, answer review comments with fixup commits, and compare squash, merge and rebase merging with real output.
  5. 38 Forks, Upstreams and Contributing Learn the fork workflow: what a fork is, adding an upstream remote, syncing your fork, rebasing a pull request, and how maintainers fetch contributions. Runs locally.
  6. 39 Submodules, Subtrees and Monorepos Learn how to share code between Git repositories: submodule add, clone and update, common pitfalls, subtree merging, sparse checkout and the monorepo versus polyrepo trade-off.
  7. 40 Worktrees and Multiple Working Directories Use git worktree to check out several branches in separate folders sharing one repository: add, list, remove, hotfix mid-feature, locking, and worktrees versus clones and stash.
  8. 41 git bundle and git archive Move Git history without a server with git bundle, and export clean snapshots as zip or tar with git archive: create, verify, clone, fetch, prefixes and export-ignore.
  9. 42 Branching Strategies: Git Flow, GitHub Flow, Trunk-Based Compare Git Flow, GitHub Flow and trunk-based development: how each model uses branches, releases and hotfixes, and how to pick the right one for your team.

Git Internals

  1. 43 Git Objects: Blobs, Trees, Commits and Tags Look inside Git's object database. Learn blobs, trees, commits and tags, how object IDs are computed, and build a commit by hand with hash-object and commit-tree.
  2. 44 References, HEAD and the .git Directory Learn how branches, tags and HEAD are just files in .git. Read refs by hand, use update-ref and symbolic-ref, understand packed-refs and tour the .git directory.
  3. 45 The Index, Packfiles and Garbage Collection Understand the Git index file, loose objects versus packfiles, delta compression, git gc, prune and repository size. Inspect everything with real commands.
  4. 46 Transfer Protocols and How Fetch and Push Work See how Git talks to remotes: URLs and protocols, refspecs, what fetch and push transfer, shallow and partial clones, and offline transfer with git bundle.
  5. 47 How Merge, Rebase and Diff Work Inside Learn the three-way merge algorithm, merge-base, the ort strategy, conflict markers, diff algorithms, rename detection and how rebase replays commits.
  6. 48 Scalar, fsmonitor and Commit-Graph for Big Repos Speed up Git on huge repositories: the commit-graph file, Bloom filters, untracked cache, the fsmonitor daemon, background maintenance and the Scalar command.

Customizing and Automating Git

  1. 49 Aliases and Everyday Productivity Create Git aliases and shell aliases, build custom git subcommands, and set the config options that remove daily friction: rerere, autostash, pull.rebase and more.
  2. 50 Git Hooks Learn Git hooks with runnable examples: pre-commit, commit-msg, pre-push, post-merge and server-side pre-receive, core.hooksPath, git hook run, --no-verify and their limits.
  3. 51 .gitattributes, Line Endings and Large Files Learn .gitattributes: fix CRLF/LF line endings, mark binary files, export-ignore, custom diff and merge drivers, clean/smudge filters, and how Git LFS stores large files.
  4. 52 Signing, Credentials and Security Sign commits and tags with GPG or SSH, understand credential helpers and SSH vs HTTPS, find and handle secrets in history, and protect branches. Runnable demos included.
  5. 53 Large Repositories: Shallow, Partial and Sparse Make Git fast on huge repositories: shallow clones with --depth, partial clones with --filter, sparse-checkout, commit-graph, fsmonitor and Scalar. Local demos you can run.
  6. 54 Git Notes Learn git notes: add, show, edit and remove notes on commits without changing hashes, use namespaces, display notes in git log, push them and merge them.
  7. 55 Git LFS Workflows Use Git LFS in practice: how pointers and the LFS store work, tracking patterns, migrating existing history, partial fetches, file locking, hosting quotas and CI.
  8. 56 Conventional Commits and Changelogs Write structured commit messages with Conventional Commits, derive the next semantic version from history, enforce the format with a hook and generate a changelog.

GitHub and Platforms

  1. 57 GitHub Basics Learn what GitHub adds to Git: repositories, remotes over HTTPS and SSH, README and community files, issues, pull requests, Actions and Pages, with local demos you can run.
  2. 58 GitHub Actions: CI for Your Repository Learn GitHub Actions: workflow YAML anatomy, triggers, jobs and steps, matrix builds, caching, secrets, artifacts and reusable workflows, with a runnable YAML sanity checker.
  3. 59 Issues, Projects and Project Management Learn how issues, labels, milestones, templates and project boards connect to Git commits. Link commits with Fixes #12, lint messages and cut release notes.
  4. 60 GitLab, Bitbucket and Self-Hosting Compare GitHub, GitLab, Bitbucket and Gitea, see how merge requests differ from pull requests, mirror and migrate repositories with plain Git, and learn self-hosting basics.
  5. 61 Contributing to Open Source A practical guide to your first open-source contribution: find a project, read CONTRIBUTING, fork and branch, write a clean pull request, handle review, and understand licenses and semver.
  6. 62 Git with Jenkins and Other CI Servers How CI servers like Jenkins, TeamCity and GitLab CI use Git: webhooks versus polling, what a pipeline checkout really does, shallow clones, clean workspaces and credentials.
  7. 63 Deploying with Git Deploy from Git: push-to-deploy with a bare repo and post-receive hook, release folders with atomic symlinks, release branches and tags, and safe rollbacks with revert.
  8. 64 Git Supply-Chain Security Protect your software supply chain with Git - protected branches, signed tags, secret scanning, pinned dependencies and update bots - with runnable server-side rule demos.

Troubleshooting and Recipes

  1. 65 Fixing Common Git Mistakes Fix the Git mistakes everyone makes: wrong branch, bad message, forgotten file, leaked secret, accidental merge, early push, detached HEAD and lost commits, with runnable repros.
  2. 66 Git Recipes and One-Liners A cookbook of Git recipes with runnable output: squash commits, find a deleted file, compare branches, clean merged branches, archive, count authors, make patches, sync a fork.
  3. 67 Troubleshooting: Errors and What They Mean Decode common Git errors: non-fast-forward, divergent branches, unrelated histories, files would be overwritten, index.lock, safe.directory, line endings, and repairing a corrupted repository.
  4. 68 Repository Maintenance and Performance Keep a Git repository small and fast: loose vs packed objects, git gc and git maintenance, finding large files in history, cleaning bloat, commit-graph and fetch.prune.
  5. 69 Removing Secrets and Large Files from History Found a password or a huge file in your Git history? Learn to find it, rotate the credential, rewrite history with filter-repo or filter-branch and handle the force-push.

Projects

  1. 70 Project: A Repository From Scratch Build a small project's history on purpose: first commits, a feature branch, a merge, annotated release tags and a changelog generated from git log, in four runnable stages.
  2. 71 Project: Simulating a Team Workflow Play both sides of a team workflow in one script: a bare remote, two clones, feature branches, pull requests as merges, review by diff, a merge conflict and a rejected push.
  3. 72 Project: Release Automation Script Write release.sh: pick the next semantic version from commit messages, build a changelog, tag the release, support dry runs and hotfix release branches, with guard rails.
  4. 73 Project: Build a Tiny Git Build a working mini version control system in about 160 lines of Bash: a content-addressable object store, index, commits, log, status, restore and integrity check, compared with real Git.
  5. 74 Project: Quality Gates with Hooks Build a team's quality gates with Git hooks: a pre-commit check of staged files, a commit-msg format check, a pre-push test run, a shared hooks directory and automated tests for the hooks.

Practice and Review

  1. 75 Git Cheat Sheet A task-based Git cheat sheet: setup, snapshots, branches, inspection, undo, remotes, rewriting and internals, with decision tables and runnable examples.
  2. 76 Practice Problems: Commits, Branches and Merges Fifteen graded Git exercises on commits, staging, undo, branches, merges, conflicts, stash, tags and cherry-pick, each with a hint and a verified runnable solution.
  3. 77 Practice Problems: Rewriting, Remotes and Internals Fifteen advanced Git exercises on squashing, rebase, reflog recovery, filter-branch, bare remotes, force-with-lease, plumbing commands and bisect, with verified solutions.
  4. 78 Git Interview Questions and Answers Fifty Git interview questions with concise answers and runnable demos: merge vs rebase, reset modes, internals, workflows and recovery, from basic to advanced.