Git & GitHub
Learn Git from the three areas and your first commit to branching, rebasing, recovering lost work and how Git stores history, then GitHub: pull requests, review, branch protection, and automation with Actions. Sixty-five lessons around one small project.
Why version control existsThe folder-copy problem that made version control necessary, and the three ideas (history, branches, sharing) that a tool like Git adds on top.Installing and configuring GitInstall Git, set the name, email, editor and default branch it stamps on your work, and learn the three config levels and how to see which one wins.The three areas of GitWorking directory, staging area and repository: where a change lives at each step, and how to read git status and git diff as a map of those three places.Your first repository and commitTurn a folder into a Git repository with git init, make two commits for tinynotes, and learn what the hidden .git folder and git status are telling you.Reading history with log and diffUse git log, git diff and git show to see what changed, when and why, and learn the three comparisons git diff makes: unstaged, staged and between commits.How Git stores historyGit stores snapshots, not diffs: commits point to trees, trees point to blobs, and every object is named by a hash of its content. See it with git cat-file.Staging precisely with add -pUse git add -p to stage individual hunks of a file, split a hunk further, and keep each commit about one thing even when your edits were tangled.Writing good commit messagesWrite commit messages that still make sense in six months: a short imperative subject, a body that explains why, and one idea per commit.Ignoring files with .gitignoreKeep generated files, secrets and local data out of Git with .gitignore: how patterns match, how to check them, and why a tracked file ignores your ignore rule.Undoing uncommitted changesUse git restore to discard edits and unstage files, and git clean to remove untracked files, plus which of these can never be taken back.Amending the last commitFix a typo in the last commit message or fold in a forgotten change with git commit --amend, and understand why it replaces the commit instead of editing it.Renaming, moving and deleting filesUse git mv and git rm to rename, move and delete tracked files, and learn that Git detects renames by comparing content rather than recording them.What a branch isA Git branch is a 41-byte file holding one commit ID. See branches, HEAD and the commit graph in .git, and learn why creating and switching branches is instant.Creating and switching branchesCreate, switch, rename and delete branches with git switch and git branch, and see what Git does with uncommitted changes when you switch.Merging: fast-forward and three-wayCombine branches with git merge, and see why Git sometimes just moves a pointer (fast-forward) and sometimes builds a two-parent merge commit (three-way).Resolving merge conflictsRead conflict markers, choose or combine the two sides, and finish or abort a merge, including the mistake of committing the markers themselves.Rebasing a branchReplay a branch's commits on top of another branch with git rebase, see why their IDs change, and handle a conflict mid-rebase with continue, skip or abort.Merge or rebase: choosingCompare merge and rebase on the same branch, see the two history shapes, and learn the one rule that decides which to use: has anyone else got these commits?Stashing unfinished workShelve uncommitted changes with git stash, bring them back with pop or apply, include untracked files, and use --keep-index to test only what you staged.Cherry-picking commitsCopy a single commit onto another branch with git cherry-pick, see why the copy gets a new ID, and handle conflicts, ranges, merge commits and duplicates.Remotes, clone and originA remote is just a named URL for another copy of your repository. Learn what origin really is, what clone sets up, and how to add a remote by hand.Fetch, pull and pushMove commits between your repository and a remote: fetch to look, pull to integrate, push to publish, and what to do when a push is rejected.Upstream tracking branchesHow a local branch is linked to a remote branch, what git push -u really writes, and how to read ahead, behind and gone in git status.Force pushing safelyWhy a rewritten branch needs a force push, why --force-with-lease beats --force, and the one case where even the lease lets you overwrite a teammate.Tags and releasesMark a commit as version 1.0 with a tag. Lightweight versus annotated tags, why git push doesn't send them, and what to do about a tag you got wrong.Forks and multiple remotesContribute to a repo you can't push to: sync your fork through an upstream remote, branch from it, and set push defaults so you never push to the wrong place.Interactive rebaseRewrite a branch before sharing it: squash noise commits, fix a message, drop a mistake, and use fixup commits with autosquash, all via the rebase todo list.Reset, soft, mixed and hardMove a branch back to an earlier commit and decide what happens to the index and your files: the three modes of git reset, tested on a real repository.Reverting a commitUndo a commit that is already published by adding a new commit that reverses it, including the extra step needed for merge commits and how to reapply one.The reflog and recovering lost workUse the reflog to find commits that no branch points to any more: undo a hard reset, bring back a deleted branch, and learn when Git really does delete them.Finding a bug with bisectBinary-search your history to find the commit that introduced a bug, first by hand and then automatically with git bisect run and a test script.Blame and searching historyFind who last changed a line and why with git blame, ignore reformatting commits, and search history for when a string appeared with git log -S, -G and -L.Removing secrets from historyA committed secret stays in history after you delete the file. Rotate it first, then rewrite history, force push and clean up, with a real filter-branch run.Objects, blobs, trees and commitsBuild a commit by hand with plumbing commands to see that Git is a content-addressed store of four object types, and why identical content is only stored once.Refs, branches and HEADA branch is a 41-byte file. Look at .git/refs, HEAD as a symbolic ref, detached HEAD, packed-refs, and the reflog files, using only cat and find.Packfiles, garbage collection and repo sizeWatch loose objects become a delta-compressed packfile with git gc, find what makes a repo big, and see why deleting a large file doesn't shrink history.Git hooksRun your own scripts at key moments in Git: write pre-commit, commit-msg and pre-push hooks, share them via core.hooksPath, and why hooks aren't security.Configuration, aliases and attributesLearn Git's layered config files, write aliases for common commands, switch identity by directory with includeIf, and use .gitattributes for line endings.WorktreesCheck out several branches of one repository at once in separate folders with git worktree, no stashing or recloning, and learn to remove them cleanly.Submodules and subtreesInclude one repository inside another at a pinned commit with submodules, or copy it in with subtree. See how each is stored, what a clone gets, and the traps.Large files and Git LFSWhy big binary files bloat a repository forever, how Git LFS swaps them for pointer files using clean and smudge filters, and what I could and could not run.Partial clones and sparse checkoutWork in a huge repository without downloading all of it: blobless partial clones, sparse checkout of one folder, shallow clones, and the trade-offs of each.Signing commits and tagsProve who made a commit or tag by signing it with an SSH key, set up allowed signers, read the G, U and N statuses, and see what rewriting does to signatures.Trunk-based developmentKeep one main branch that is always releasable, merge small changes into it every day, and hide unfinished work behind a flag instead of a long-lived branch.Feature branches and GitflowCompare the three common branching models, feature branches, GitHub flow and Gitflow, and pick the lightest one that fits how you release.Conventional Commits and semantic versioningWrite commit messages in a fixed shape so a tool can read them, and use them to decide the next version number: patch, minor or major.GitHub accounts, SSH keys and authenticationProve who you are to GitHub from the command line: generate an ed25519 SSH key, add the public half to your account, and know when HTTPS tokens fit better.Creating and publishing a repositoryTurn a local Git project into a GitHub repository: create an empty remote, connect it with git remote add, push main, and choose visibility, license and README.Pull requestsA pull request asks to merge one branch into another and gives the team a place to review and test first. Learn what it contains and how to write one.Code review on GitHubReview a pull request line by line: batch comments, propose exact edits with suggestions, choose Comment, Approve or Request changes, and respond well.Merge methods: squash, rebase and mergeGitHub offers three ways to merge a pull request. See the history each leaves, why a squashed branch looks unmerged to Git, and which suits your team.Issues and projectsTrack bugs, ideas and tasks as GitHub issues, link them to pull requests so merging closes them, and plan the work on a Projects board or table.Branch protection and rulesetsTurn 'main must stay green' into a rule GitHub enforces: require pull requests, reviews and passing checks, and block force pushes and deletion.CODEOWNERS and templatesRoute reviews to the right people with a CODEOWNERS file, and give contributors issue forms and a pull request template so reports arrive with what you need.The GitHub CLIUse gh to create repositories, open and merge pull requests, file issues and watch Actions runs from the terminal, and call any GitHub API endpoint with gh api.GitHub PagesPublish a static site from a repository: choose a branch or a GitHub Actions workflow as the source, know the limits, and keep unwanted files out.Dependabot and dependency updatesKeep dependencies and Actions current with Dependabot: alerts, security and version updates, a working dependabot.yml, and reviewing its pull requests.Secret scanning and code securityWhy a pushed secret is a leaked secret, how secret scanning and push protection catch it, and where CodeQL and dependency review fit.Workflows, triggers, jobs and stepsWrite your first GitHub Actions workflow: a YAML file that runs the tests when you push or open a pull request, built from triggers, jobs and steps.Runners and the marketplaceChoose where a workflow runs, GitHub-hosted or self-hosted, and learn how marketplace actions are versioned, found and trusted before you use them.Secrets, variables and contextsGive a workflow credentials and settings safely: secrets, variables, the GITHUB_TOKEN, and the contexts behind every ${{ }} expression.Caching, artifacts and matrix buildsSpeed up CI by caching dependencies, pass build output between jobs as artifacts, and test several Node versions with a matrix, avoiding name clashes.Reusable workflows and composite actionsStop copying the same YAML between repositories: share whole jobs with reusable workflows, share a few steps with composite actions, and know which one to pick.Deploying from Actions with OIDCDeploy to a cloud account without a long-lived key in GitHub: let each workflow run prove its identity with OpenID Connect and get a short-lived credential.Hardening your workflowsMake a workflow a hard target: least-privilege tokens, SHA-pinned actions, no script injection from pull request text, and care with privileged triggers.
What Git is
- Why version control existsThe folder-copy problem that made version control necessary, and the three ideas (history, branches, sharing) that a tool like Git adds on top.
- Installing and configuring GitInstall Git, set the name, email, editor and default branch it stamps on your work, and learn the three config levels and how to see which one wins.
- The three areas of GitWorking directory, staging area and repository: where a change lives at each step, and how to read git status and git diff as a map of those three places.
- Your first repository and commitTurn a folder into a Git repository with git init, make two commits for tinynotes, and learn what the hidden .git folder and git status are telling you.
- Reading history with log and diffUse git log, git diff and git show to see what changed, when and why, and learn the three comparisons git diff makes: unstaged, staged and between commits.
- How Git stores historyGit stores snapshots, not diffs: commits point to trees, trees point to blobs, and every object is named by a hash of its content. See it with git cat-file.
Everyday work
- Staging precisely with add -pUse git add -p to stage individual hunks of a file, split a hunk further, and keep each commit about one thing even when your edits were tangled.
- Writing good commit messagesWrite commit messages that still make sense in six months: a short imperative subject, a body that explains why, and one idea per commit.
- Ignoring files with .gitignoreKeep generated files, secrets and local data out of Git with .gitignore: how patterns match, how to check them, and why a tracked file ignores your ignore rule.
- Undoing uncommitted changesUse git restore to discard edits and unstage files, and git clean to remove untracked files, plus which of these can never be taken back.
- Amending the last commitFix a typo in the last commit message or fold in a forgotten change with git commit --amend, and understand why it replaces the commit instead of editing it.
- Renaming, moving and deleting filesUse git mv and git rm to rename, move and delete tracked files, and learn that Git detects renames by comparing content rather than recording them.
Branching and merging
- What a branch isA Git branch is a 41-byte file holding one commit ID. See branches, HEAD and the commit graph in .git, and learn why creating and switching branches is instant.
- Creating and switching branchesCreate, switch, rename and delete branches with git switch and git branch, and see what Git does with uncommitted changes when you switch.
- Merging: fast-forward and three-wayCombine branches with git merge, and see why Git sometimes just moves a pointer (fast-forward) and sometimes builds a two-parent merge commit (three-way).
- Resolving merge conflictsRead conflict markers, choose or combine the two sides, and finish or abort a merge, including the mistake of committing the markers themselves.
- Rebasing a branchReplay a branch's commits on top of another branch with git rebase, see why their IDs change, and handle a conflict mid-rebase with continue, skip or abort.
- Merge or rebase: choosingCompare merge and rebase on the same branch, see the two history shapes, and learn the one rule that decides which to use: has anyone else got these commits?
- Stashing unfinished workShelve uncommitted changes with git stash, bring them back with pop or apply, include untracked files, and use --keep-index to test only what you staged.
- Cherry-picking commitsCopy a single commit onto another branch with git cherry-pick, see why the copy gets a new ID, and handle conflicts, ranges, merge commits and duplicates.
Remotes
- Remotes, clone and originA remote is just a named URL for another copy of your repository. Learn what origin really is, what clone sets up, and how to add a remote by hand.
- Fetch, pull and pushMove commits between your repository and a remote: fetch to look, pull to integrate, push to publish, and what to do when a push is rejected.
- Upstream tracking branchesHow a local branch is linked to a remote branch, what git push -u really writes, and how to read ahead, behind and gone in git status.
- Force pushing safelyWhy a rewritten branch needs a force push, why --force-with-lease beats --force, and the one case where even the lease lets you overwrite a teammate.
- Tags and releasesMark a commit as version 1.0 with a tag. Lightweight versus annotated tags, why git push doesn't send them, and what to do about a tag you got wrong.
- Forks and multiple remotesContribute to a repo you can't push to: sync your fork through an upstream remote, branch from it, and set push defaults so you never push to the wrong place.
Rewriting and recovering
- Interactive rebaseRewrite a branch before sharing it: squash noise commits, fix a message, drop a mistake, and use fixup commits with autosquash, all via the rebase todo list.
- Reset, soft, mixed and hardMove a branch back to an earlier commit and decide what happens to the index and your files: the three modes of git reset, tested on a real repository.
- Reverting a commitUndo a commit that is already published by adding a new commit that reverses it, including the extra step needed for merge commits and how to reapply one.
- The reflog and recovering lost workUse the reflog to find commits that no branch points to any more: undo a hard reset, bring back a deleted branch, and learn when Git really does delete them.
- Finding a bug with bisectBinary-search your history to find the commit that introduced a bug, first by hand and then automatically with git bisect run and a test script.
- Blame and searching historyFind who last changed a line and why with git blame, ignore reformatting commits, and search history for when a string appeared with git log -S, -G and -L.
- Removing secrets from historyA committed secret stays in history after you delete the file. Rotate it first, then rewrite history, force push and clean up, with a real filter-branch run.
Inside Git
- Objects, blobs, trees and commitsBuild a commit by hand with plumbing commands to see that Git is a content-addressed store of four object types, and why identical content is only stored once.
- Refs, branches and HEADA branch is a 41-byte file. Look at .git/refs, HEAD as a symbolic ref, detached HEAD, packed-refs, and the reflog files, using only cat and find.
- Packfiles, garbage collection and repo sizeWatch loose objects become a delta-compressed packfile with git gc, find what makes a repo big, and see why deleting a large file doesn't shrink history.
- Git hooksRun your own scripts at key moments in Git: write pre-commit, commit-msg and pre-push hooks, share them via core.hooksPath, and why hooks aren't security.
- Configuration, aliases and attributesLearn Git's layered config files, write aliases for common commands, switch identity by directory with includeIf, and use .gitattributes for line endings.
Advanced repositories
- WorktreesCheck out several branches of one repository at once in separate folders with git worktree, no stashing or recloning, and learn to remove them cleanly.
- Submodules and subtreesInclude one repository inside another at a pinned commit with submodules, or copy it in with subtree. See how each is stored, what a clone gets, and the traps.
- Large files and Git LFSWhy big binary files bloat a repository forever, how Git LFS swaps them for pointer files using clean and smudge filters, and what I could and could not run.
- Partial clones and sparse checkoutWork in a huge repository without downloading all of it: blobless partial clones, sparse checkout of one folder, shallow clones, and the trade-offs of each.
- Signing commits and tagsProve who made a commit or tag by signing it with an SSH key, set up allowed signers, read the G, U and N statuses, and see what rewriting does to signatures.
Team workflows
- Trunk-based developmentKeep one main branch that is always releasable, merge small changes into it every day, and hide unfinished work behind a flag instead of a long-lived branch.
- Feature branches and GitflowCompare the three common branching models, feature branches, GitHub flow and Gitflow, and pick the lightest one that fits how you release.
- Conventional Commits and semantic versioningWrite commit messages in a fixed shape so a tool can read them, and use them to decide the next version number: patch, minor or major.
GitHub collaboration
- GitHub accounts, SSH keys and authenticationProve who you are to GitHub from the command line: generate an ed25519 SSH key, add the public half to your account, and know when HTTPS tokens fit better.
- Creating and publishing a repositoryTurn a local Git project into a GitHub repository: create an empty remote, connect it with git remote add, push main, and choose visibility, license and README.
- Pull requestsA pull request asks to merge one branch into another and gives the team a place to review and test first. Learn what it contains and how to write one.
- Code review on GitHubReview a pull request line by line: batch comments, propose exact edits with suggestions, choose Comment, Approve or Request changes, and respond well.
- Merge methods: squash, rebase and mergeGitHub offers three ways to merge a pull request. See the history each leaves, why a squashed branch looks unmerged to Git, and which suits your team.
- Issues and projectsTrack bugs, ideas and tasks as GitHub issues, link them to pull requests so merging closes them, and plan the work on a Projects board or table.
- Branch protection and rulesetsTurn 'main must stay green' into a rule GitHub enforces: require pull requests, reviews and passing checks, and block force pushes and deletion.
- CODEOWNERS and templatesRoute reviews to the right people with a CODEOWNERS file, and give contributors issue forms and a pull request template so reports arrive with what you need.
- The GitHub CLIUse gh to create repositories, open and merge pull requests, file issues and watch Actions runs from the terminal, and call any GitHub API endpoint with gh api.
The GitHub platform
- GitHub PagesPublish a static site from a repository: choose a branch or a GitHub Actions workflow as the source, know the limits, and keep unwanted files out.
- Dependabot and dependency updatesKeep dependencies and Actions current with Dependabot: alerts, security and version updates, a working dependabot.yml, and reviewing its pull requests.
- Secret scanning and code securityWhy a pushed secret is a leaked secret, how secret scanning and push protection catch it, and where CodeQL and dependency review fit.
GitHub Actions
- Workflows, triggers, jobs and stepsWrite your first GitHub Actions workflow: a YAML file that runs the tests when you push or open a pull request, built from triggers, jobs and steps.
- Runners and the marketplaceChoose where a workflow runs, GitHub-hosted or self-hosted, and learn how marketplace actions are versioned, found and trusted before you use them.
- Secrets, variables and contextsGive a workflow credentials and settings safely: secrets, variables, the GITHUB_TOKEN, and the contexts behind every ${{ }} expression.
- Caching, artifacts and matrix buildsSpeed up CI by caching dependencies, pass build output between jobs as artifacts, and test several Node versions with a matrix, avoiding name clashes.
- Reusable workflows and composite actionsStop copying the same YAML between repositories: share whole jobs with reusable workflows, share a few steps with composite actions, and know which one to pick.
- Deploying from Actions with OIDCDeploy to a cloud account without a long-lived key in GitHub: let each workflow run prove its identity with OpenID Connect and get a short-lived credential.
- Hardening your workflowsMake a workflow a hard target: least-privilege tokens, SHA-pinned actions, no script injection from pull request text, and care with privileged triggers.