Notes
All notes

Git and GitHub: from commits to collaboration

Almost everyone uses Git daily and only a few can explain what it actually stores. That gap becomes visible the first time a rebase goes wrong, a force-push eats a teammate’s work, or a merge conflict appears in a file nobody touched. Git is not a set of magic incantations; it is a small content-addressed database with a graph on top, and once you see the graph the commands stop being arbitrary.

This guide follows the roadmap.sh/git-github path in one post: version control theory, the Git object model, branching and merging, rebasing and history rewriting, undoing changes, remotes, tags, submodules, hooks, and the GitHub platform from pull requests to Actions. Commands are interleaved with the reasoning, and self-test questions follow each section.

Version control, and what Git stores

Version control records the history of a project so you can inspect, compare, and recover any past state, and so several people can work in parallel without overwriting each other. Older centralized systems (SVN, CVS) kept one server-side history; Git is distributed, meaning every clone is a full repository with the complete history.

Git’s data model is the part worth learning. Everything is stored as one of four immutable, content-addressed objects:

Content-addressed means the object’s name is the SHA hash of its contents. Identical content is stored once, and any change to a file changes every hash above it — which is why Git commits are immutable and why tampering is detectable. A branch is just a movable pointer to a commit, and HEAD points at the branch you are on.

\begin{tikzpicture}[font=\rmfamily, >=stealth,
  c/.style={draw, thick, circle, minimum size=0.6cm, font=\scriptsize\ttfamily, inner sep=0pt},
  a/.style={->, thick}]
  \node[c, fill=blue!12] (a) at (0,0) {a1};
  \node[c, fill=blue!12] (b) at (1.4,0) {b2};
  \node[c, fill=blue!12] (c) at (2.8,0) {c3};
  \draw[a] (a) -- (b); \draw[a] (b) -- (c);
  \node[font=\small, text=green!45!black, anchor=south] at (2.8,0.5) {main};
  \node[c, fill=orange!18] (d) at (2.8,-1.0) {d4};
  \draw[a] (c) -- (d);
  \node[font=\small, text=orange!70!black, anchor=north] at (2.8,-1.5) {feature};
  \node[font=\rmfamily\small, text=black!60, anchor=north] at (1.4,-0.6) {commits form a DAG};
\end{tikzpicture}

Why Git over other VCS: it is fast, fully offline-capable, cheap to branch, and its merging is excellent because it tracks snapshots and can find a common ancestor, called the merge base.

QQuestionWhat does Git actually store, and what is a branch really?
ASolution

Four immutable, content-addressed objects: blob (file contents), tree (directory listing), commit (snapshot + metadata + parent pointers), and tag. Identical content is stored once. A branch is just a movable pointer to a commit, and HEAD points at the current branch — which is why branching is instant.

QQuestionWhat is the difference between a distributed and a centralized VCS like SVN?
ASolution

In a distributed VCS every clone contains the full history and can commit and branch offline; in a centralized VCS the history lives on one server and most operations need the network. Distributed also means merges are common and cheap, because each clone can compute the merge base locally.

Installing and configuring Git

Install from your package manager or git-scm.com, then set your identity once. Every commit records it.

git config --global user.name "Your Name"
git config --global user.email "you@example.com"
git config --global init.defaultBranch main
git config --global core.editor "vim"
git config --list            # inspect

Useful extras: alias for shortcuts (git config --global alias.st status), pull.rebase to choose merge-or-rebase on pull, and a global .gitignore for editor/OS files. Credentials are handled by a credential helper (or SSH keys) — never commit them.

QQuestionHow do you set your Git identity, and why does it matter?
ASolution

git config --global user.name "…" and user.email "…". Every commit records them, so a wrong identity misattributes your work. Use --global for your machine default and per-repository config (no --global) when a project needs a different identity.

QQuestionWhat are Git’s three config scopes?
ASolution

System (/etc/gitconfig, all users), global (~/.gitconfig, your user), and local (.git/config, one repository). Local overrides global overrides system, which is how a repo can override your default identity or editor.

Repositories, the three trees, and the core workflow

A repository is a project tracked by Git: a .git directory plus your working files. git init creates one; git clone copies a remote.

Git has three places a change can live, often called the three trees:

The everyday loop moves content left to right: edit, add to stage, commit to record. The index is what makes Git powerful: you choose exactly what goes into a commit, not whatever happens to be on disk.

git init                     # create a repo here
git status                   # working dir vs index vs HEAD
git add file.py              # stage a file (or: git add -p for hunks)
git commit -m "Add parser"   # snapshot the index
git diff                     # working dir vs index
git diff --staged            # index vs HEAD
\begin{tikzpicture}[font=\rmfamily, >=stealth,
  b/.style={draw, thick, rounded corners=3pt, minimum width=2.1cm, minimum height=0.7cm, font=\small\ttfamily},
  a/.style={->, thick}]
  \node[b, fill=blue!10] (w) at (0,0) {working dir};
  \node[b, fill=orange!16] (i) at (3.0,0) {index};
  \node[b, fill=green!14] (h) at (6.0,0) {HEAD};
  \draw[a] (w) -- node[above, font=\scriptsize] {git add} (i);
  \draw[a] (i) -- node[above, font=\scriptsize] {git commit} (h);
  \draw[a, dashed] (h) to[bend left=30] node[below, font=\scriptsize] {checkout} (w);
\end{tikzpicture}

.gitignore keeps generated and secret files out of git status; list patterns (node_modules/, *.log, .env). Commit messages should be imperative and explain the why: Fix off-by-one in pagination, not fixed stuff.

QQuestionWhat are Git’s three trees, and what is the index for?
ASolution

The working directory (files on disk), the index/staging area (the proposed next commit), and HEAD (the last commit on the current branch). The index lets you choose exactly which changes go into a commit (git add -p for individual hunks) instead of committing everything on disk.

QQuestionWhat is the difference between git diff, git diff --staged, and git status?
ASolution

git diff compares the working directory to the index (unstaged changes); git diff --staged (or --cached) compares the index to HEAD (what would be committed); git status is a summary of both plus untracked files.

Branching

A branch is a lightweight pointer to a commit; creating one is writing a 40-byte file, not copying the code. HEAD points at the current branch, and committing advances that pointer. This is why branching in Git is instant and why merging is common rather than feared.

git branch feature/login     # create
git switch feature/login     # move HEAD (or: git checkout -b feature/login)
git branch                   # list local branches
git switch -c hotfix main    # branch off main
git branch -d feature/login  # delete a merged branch

Detached HEAD is the state where HEAD points directly at a commit instead of a branch — for example after git checkout <commit> or checking out a tag. Commits made there belong to no branch and can be lost when you switch away. Inspect freely, but create a branch before committing: git switch -c rescue.

QQuestionWhat is HEAD, and what is a detached HEAD?
ASolution

HEAD is a reference to the current branch (or commit). Detached HEAD is when it points directly at a commit — after checking out a commit or tag — so new commits belong to no branch and can be lost when you switch away. Inspect freely, but git switch -c <name> before committing.

QQuestionHow do you recover commits made in a detached HEAD?
ASolution

Find the commit hash with git reflog, then git switch -c rescue <hash> to attach a branch to it. As long as the objects have not been garbage-collected, the work is recoverable.

Merging

A merge integrates another branch into the current one. Git finds the merge base (the common ancestor) and combines the two histories:

git switch main
git merge feature/login
\begin{tikzpicture}[font=\rmfamily, >=stealth,
  c/.style={draw, thick, circle, minimum size=0.5cm, font=\scriptsize, inner sep=0pt},
  a/.style={->, thick}]
  \node[c, fill=blue!12] (a) at (0,0) {};
  \node[c, fill=blue!12] (b) at (1.1,0) {};
  \node[c, fill=orange!18] (f) at (1.1,-1.0) {};
  \node[c, fill=orange!18] (g) at (2.2,-1.0) {};
  \node[c, fill=green!20] (m) at (2.2,0) {};
  \draw[a] (a) -- (b); \draw[a] (b) -- (f); \draw[a] (f) -- (g);
  \draw[a] (b) -- (m); \draw[a] (g) -- (m);
  \node[font=\rmfamily\small, text=black!60, anchor=north] at (1.1,-1.6) {three-way merge creates a commit with two parents};
\end{tikzpicture}

git merge --no-ff forces a merge commit even when a fast-forward is possible, which keeps a visible record that a branch existed — a common team policy.

QQuestionWhat is the difference between a fast-forward and a three-way merge?
ASolution

A fast-forward happens when the target branch has not diverged: Git just moves its pointer, leaving linear history and no merge commit. A three-way merge happens when both branches moved: Git uses the merge base and the two tips to build a merge commit with two parents, preserving both histories.

QQuestionWhat does git merge --no-ff do, and what is a squash merge?
ASolution

--no-ff forces a merge commit even when a fast-forward is possible, keeping a visible record that a branch existed. A squash merge combines all of a branch’s commits into one commit on the target, giving linear history but discarding the branch’s individual commits.

Merge conflicts

A conflict happens when both sides changed the same lines, or one side deleted what the other edited. Git cannot know the intent, so it marks the file and pauses the merge:

<<<<<<< HEAD
timeout = 30
=======
timeout = 60
>>>>>>> feature/login

Edit the file to the intended result, remove the markers, then stage and finish:

git status                    # list conflicted files
# edit files, then...
git add resolved_file.py
git commit                    # completes the merge
git merge --abort             # or back out entirely

Resolve conflicts by understanding both changes, not by blindly picking a side. A merge tool (git mergetool) or your editor’s three-pane view helps. After resolving, run the tests — a conflict resolution is new, untested code.

QQuestionWhat causes a merge conflict, and how do you resolve one?
ASolution

A conflict occurs when both sides changed the same lines of a file (or one deleted what the other edited) and Git cannot infer intent. It inserts <<<<<<</=======/>>>>>>> markers and pauses. Edit to the intended result, remove the markers, git add the file, then git commit (or git merge --abort to back out). Re-run the tests afterward.

QQuestionWhy should you run tests after resolving a conflict?
ASolution

A conflict resolution is new code that no one has executed — the combination of both changes may not have been tested. The merge can be textually clean and semantically broken.

Rebasing and rewriting history

Rebase replays your commits on top of another base, producing a linear history. Instead of creating a merge commit, Git copies each commit and moves the branch pointer:

git switch feature
git rebase main               # replay feature commits on top of main

The golden rule: do not rebase commits that others may have based work on. Rebase creates new commits (new hashes); anyone who pulled the old ones now has divergent history, which is why a rebase of a shared branch requires a force-push and causes pain.

Interactive rebase is the history-editing tool:

git rebase -i HEAD~3          # edit, reorder, squash, drop the last 3 commits
# pick / reword / edit / squash / fixup / drop

Other rewriting commands:

git commit --amend            # change the last commit message/content
git filter-repo --path secrets.env --invert-paths   # purge a file from all history
git push --force-with-lease   # safer force-push: refuses if the remote moved

git push --force overwrites the remote branch. Prefer --force-with-lease, which fails if someone else pushed in the meantime, and never force-push a shared branch (like main) without coordination.

QQuestionWhat is the difference between git merge and git rebase?
ASolution

merge combines two branches with a merge commit, preserving the true (often non-linear) history. rebase replays your commits onto a new base, producing new commits with new hashes and a linear history. Merge is safe on shared branches; rebase rewrites history and is for local/unshared commits.

QQuestionWhat is the golden rule of rebasing?
ASolution

Do not rebase commits that others may have based work on. Rebasing creates new hashes; anyone who pulled the old commits ends up with divergent history, forcing a force-push and causing pain. Rebase your own feature branch, not a shared one.

QQuestionWhat is the difference between git push --force and --force-with-lease?
ASolution

--force overwrites the remote branch unconditionally, potentially destroying teammates’ commits. --force-with-lease refuses if the remote has moved since you last fetched, which catches the case where someone else pushed. Prefer the lease, and never force a shared branch without coordination.

Cherry-pick and patches

Cherry-pick copies a specific commit onto the current branch — useful for back-porting a fix without merging a whole branch:

git cherry-pick a1b2c3d
git cherry-pick main~2..main   # a range

A patch is a commit serialized as text, for email-based or offline workflows:

git format-patch main --stdout > fix.patch
git apply fix.patch            # apply a diff without committing
git am fix.patch               # apply and commit a format-patch file

Patches and cherry-picks duplicate changes (new hashes), so use them deliberately rather than as a habit.

QQuestionWhen would you use git cherry-pick?
ASolution

To copy a specific commit onto the current branch without merging the whole source branch — typically back-porting a bug fix from main to a release branch. It creates a new commit with a new hash, so use it deliberately; overuse duplicates history and causes conflicts later.

QQuestionWhat is the difference between git apply and git am?
ASolution

git apply applies a plain diff to the working tree without creating a commit; git am applies a git format-patch file that includes commit metadata (author, message) and commits it. Use am for patch series received by email, apply for a bare diff.

Undoing changes

The single most confusing corner of Git is undo, because there are several targets. First decide what you are undoing: the working directory, the index, a commit, or a published commit.

git restore (or the older git checkout -- <file>) discards working-dir changes; git restore --staged unstages without touching the file.

git reset moves the branch pointer and optionally the index and working dir:

Command Moves HEAD Index Working dir
git reset --soft HEAD~1 yes keeps keeps
git reset --mixed HEAD~1 (default) yes resets keeps
git reset --hard HEAD~1 yes resets discards

--soft is “undo the commit, keep the changes staged”; --mixed keeps them unstaged; --hard throws them away. --hard is destructive — it deletes uncommitted work.

git revert is the safe undo for published history: it creates a new commit that inverts the target commit, so the original stays in history.

git revert a1b2c3d             # public history: add an inverse commit

The rule of thumb: reset for local, unpushed commits; revert for shared history.

\begin{tikzpicture}[font=\rmfamily, >=stealth,
  c/.style={draw, thick, circle, minimum size=0.5cm, font=\scriptsize, inner sep=0pt},
  a/.style={->, thick}]
  \node[c, fill=blue!12] (a) at (0,0) {a};
  \node[c, fill=blue!12] (b) at (1.1,0) {b};
  \node[c, fill=red!15] (c) at (2.2,0) {c};
  \node[c, fill=green!20] (d) at (3.3,0) {c'};
  \draw[a] (a) -- (b); \draw[a] (b) -- (c); \draw[a] (c) -- (d);
  \node[font=\small, text=green!45!black, anchor=south] at (3.3,0.4) {revert};
  \node[font=\small, text=red!60, anchor=north] at (2.2,-0.4) {original stays};
\end{tikzpicture}

If you lose work to a bad reset or rebase, git reflog lists every position HEAD has held. Find the lost commit and recover it with git switch -c rescue <hash> — this is why “lost” commits are usually recoverable for weeks.

QQuestionWhat is the difference between git reset --soft, --mixed, and --hard?
ASolution

All three move the branch pointer. --soft keeps the index and working tree (the changes stay staged), --mixed (the default) resets the index but keeps the working tree (changes become unstaged), and --hard resets both — discarding uncommitted work. Use --soft to redo a commit; never --hard without checking git status.

QQuestionWhat is the difference between reset, revert, and checkout/restore?
ASolution

reset moves the current branch pointer (rewriting local history). revert creates a new commit that inverts a target commit, preserving history — the safe undo for published commits. checkout/restore affect the working tree/index (discard or stage file changes) without moving the branch.

QQuestionHow do you recover a commit after a bad reset or rebase?
ASolution

git reflog lists every position HEAD has held; find the commit hash and git switch -c rescue <hash> (or git reset --hard <hash>). Unreferenced commits are usually recoverable for weeks until garbage collection.

Viewing history and diffs

git log --oneline --graph --all        # compact graph of all branches
git log --author="Ann" --since="2 weeks ago"
git log -p file.py                     # history with diffs
git show a1b2c3d                       # one commit
git blame file.py                      # last change per line
git diff main..feature                 # branch comparison
git diff a1b2c3d..b2c3d4e              # commit comparison
git diff --staged                      # staged vs HEAD

--oneline --graph is the fastest way to see whether history is linear (each commit has one parent) or non-linear (merge commits with two). If you cannot read the graph, you cannot reason about a merge.

QQuestionHow do you inspect history and find who last changed a line?
ASolution

git log --oneline --graph --all shows the commit graph compactly (linear versus merges), git log -p <file> shows a file’s history with diffs, and git blame <file> attributes each line to the last commit and author. git diff A..B compares any two commits or branches.

QQuestionHow do you see only the changes you have staged?
ASolution

git diff --staged (or --cached) compares the index to HEAD — exactly what would go into the next commit. Plain git diff shows unstaged working-tree changes only.

Stashing

Stash shelves uncommitted changes so you can switch context without committing half-done work:

git stash push -m "wip parser"    # save and clean the working tree
git stash list
git stash pop                     # apply and drop the top entry
git stash apply stash@{1}         # apply without dropping
git stash drop stash@{1}

Stash is local and temporary; it is not a backup and it does not transfer to teammates. Prefer a WIP commit on a branch for longer-lived work.

QQuestionWhat is git stash, and why is it not a backup?
ASolution

git stash saves uncommitted changes and cleans the working tree so you can switch context, then git stash pop reapplies them. It is local to your clone, not pushed, and entries can be dropped — so it is a temporary shelf, not a backup. For longer-lived work, commit to a WIP branch instead.

Remotes

A remote is a named URL to another copy of the repository (origin is the default name for where you cloned from). Local branches can track a remote branch, so pull/push know their counterpart.

git remote -v                     # list remotes
git remote add upstream https://github.com/org/repo.git
git fetch origin                  # download new commits, do NOT change your branch
git pull origin main              # fetch + integrate (merge or rebase)
git push -u origin feature        # push and set the upstream
git remote prune origin           # drop stale remote-tracking refs

The key distinction is fetch vs pull: fetch updates remote-tracking branches so you can inspect what changed; pull is fetch followed by a merge (or rebase). Fetching first is how you avoid surprise merges.

\begin{tikzpicture}[font=\rmfamily, >=stealth,
  b/.style={draw, thick, rounded corners=3pt, minimum width=2.0cm, minimum height=0.7cm, font=\small\ttfamily},
  a/.style={->, thick}]
  \node[b, fill=blue!10] (l) at (0,0) {local};
  \node[b, fill=orange!16] (r) at (4.0,0) {origin};
  \draw[a] (l) -- node[above, font=\scriptsize] {push} (r);
  \draw[a] (r) -- node[below, font=\scriptsize] {fetch / pull} (l);
\end{tikzpicture}
QQuestionWhat is the difference between git fetch and git pull?
ASolution

git fetch downloads new commits and updates remote-tracking branches without changing your working branch, so you can inspect what changed. git pull is fetch followed by an integration (merge or rebase). Fetching first avoids surprise merges.

QQuestionWhat do origin and upstream mean, and what is a tracking branch?
ASolution

origin is the default name for the remote you cloned from; upstream is a conventional name for the original repository when you are working from a fork. A tracking branch has a configured remote counterpart (git push -u sets it), so git pull/git push know where to sync.

Tags and releases

A tag is a permanent, human-readable name for a specific commit, usually a release. Lightweight tags are just pointers; annotated tags store a message, author, and date, and are the right choice for releases.

git tag v1.0.0                              # lightweight
git tag -a v1.1.0 -m "Release 1.1.0"        # annotated
git push origin v1.1.0                      # tags are not pushed by default
git push origin --tags
git checkout v1.0.0                         # inspect (detached HEAD!)

Semantic versioning (MAJOR.MINOR.PATCH) is the common convention: breaking changes, features, fixes. On GitHub, a pushed tag can become a Release with notes and downloadable assets.

QQuestionWhat is the difference between a lightweight and an annotated tag?
ASolution

A lightweight tag is just a pointer to a commit. An annotated tag is a full object with a message, author, and date, and is the correct choice for releases. Create with git tag v1.0.0 versus git tag -a v1.0.0 -m "Release".

QQuestionWhy do tags not appear on the remote after a push, and what is a GitHub Release?
ASolution

git push does not push tags by default; use git push origin <tag> or git push --tags. On GitHub, a pushed annotated tag can back a Release with notes and downloadable assets. Checking out a tag puts you in detached HEAD.

Submodules and subtrees

A submodule embeds another repository at a fixed commit inside yours, recorded as a special entry. Useful for vendored dependencies; awkward because it is not automatic.

git submodule add https://github.com/org/lib.git libs/lib
git clone --recurse-submodules <url>       # clone including submodules
git submodule update --init --recursive    # after a normal clone / when it moves

Submodules pin a commit, so updating requires moving the pointer and committing it. A subtree (via git subtree) copies the other repo’s history into yours — simpler for consumers, heavier for maintainers.

QQuestionWhat is a Git submodule, and what is the main footgun?
ASolution

A submodule embeds another repository at a pinned commit inside yours, recorded as a special entry. The footgun: cloning or pulling does not populate it, and updating requires moving the pointer. Clone with --recurse-submodules and run git submodule update --init --recursive after a normal clone.

QQuestionWhen would you choose a subtree over a submodule?
ASolution

A subtree copies the dependency’s history into your repository (via git subtree), so consumers need no special commands — simpler for them, heavier for maintainers who synchronize updates. Submodules are better when the dependency has its own release cadence and should stay separate.

Git hooks

Hooks are scripts Git runs at points in the workflow. Client-side hooks live in .git/hooks/ (not versioned) and include pre-commit, commit-msg, pre-push; server-side hooks run on the remote (GitHub exposes some via its own tooling). Typical uses: lint/format before commit, run tests before push, enforce a commit-message convention.

# .git/hooks/pre-commit (chmod +x)
#!/bin/sh
black --check . || exit 1

Hooks are a convenience, not a security boundary — they can be bypassed with --no-verify, so CI is what actually enforces rules.

QQuestionWhat are Git hooks, and what are they commonly used for?
ASolution

Scripts Git runs at workflow points. Client-side hooks live in .git/hooks/ (pre-commit, commit-msg, pre-push) and commonly run formatters/linters/tests; server-side hooks run on the remote and enforce policy. They are version-local unless installed by a tool.

QQuestionAre hooks a security control?
ASolution

No. They run locally and can be skipped with --no-verify, so they are a convenience, not enforcement. Real gates belong in CI (for example GitHub Actions, or branch protection), where they cannot be bypassed.

GitHub essentials and collaboration

GitHub hosts Git repositories and adds collaboration on top. The core units: repositories, issues (track work), pull requests (propose and review a branch), forks (your own copy of someone else’s repo), and code review (comments and approvals).

# fork on GitHub, then:
git clone git@github.com:you/repo.git
git remote add upstream https://github.com/org/repo.git
git switch -c fix/typo
git commit -am "Fix typo"
git push -u origin fix/typo
# open a pull request, get review, merge

A pull request is the central workflow: push a branch, open a PR, discuss and review, pass CI, then merge (merge commit, squash, or rebase). Common branching strategies:

Strategy Shape Fits
GitHub Flow branch → PR → merge to main small teams, continuous delivery
Git Flow long-lived develop/release/hotfix versioned releases
Trunk-based tiny branches on main, feature flags high-frequency deploys

Keep PRs small and focused; a 2,000-line PR is unreviewable and a merge-conflict magnet.

QQuestionWhat is the difference between a fork and a clone?
ASolution

Cloning copies a repository to your machine; forking creates your own copy of someone else’s repository on GitHub, which you can push branches to and open pull requests from. The fork-and-PR workflow is how external contributors propose changes.

QQuestionWhat is a pull request, and what are the common branching strategies?
ASolution

A pull request proposes merging a branch, and adds review, discussion, and CI before the merge. Strategies: GitHub Flow (branch → PR → main, continuous delivery), Git Flow (long-lived develop/release/hotfix branches for versioned releases), and trunk-based (tiny branches on main behind feature flags).

GitHub Actions and CI/CD

GitHub Actions runs workflows in response to events. A workflow is YAML in .github/workflows/, with jobs made of steps, triggered by push, pull_request, schedule, or workflow_dispatch.

name: CI
on: [push, pull_request]
jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-python@v5
        with: { python-version: "3.12" }
      - run: pip install -e ".[test]"
      - run: pytest -q

Secrets live in repository settings and are injected as environment variables (${{ secrets.TOKEN }}); a matrix runs a job across versions/OSes; caching speeds up repeated installs. CI is where lint, types, tests, and security scans actually gate merges.

QQuestionWhat is GitHub Actions, and how are secrets handled?
ASolution

A CI/CD system configured by YAML workflows in .github/workflows/, triggered by events (push, pull_request, schedule) and made of jobs and steps. Secrets are stored in repository/organization settings and injected as environment variables (${{ secrets.NAME }}), never committed. Matrix builds and dependency caching are common.

QQuestionHow do you stop broken code from reaching main?
ASolution

Combine branch protection (require reviews and passing status checks, disallow force-pushes) with a CI workflow that runs lint, type checks, tests, and security scans on every pull request. The check reports as a status that the merge is gated on.

GitHub CLI, API, webhooks, and apps

The GitHub CLI (gh) brings the platform to the terminal — the same commands this site’s publishing workflow uses:

gh auth login
gh repo create
gh pr create --title "Add feature" --body-file body.md
gh pr merge --squash --delete-branch
gh issue list
gh run watch

The API (REST and GraphQL) automates anything the UI can do; webhooks push events to your server for real-time reactions; GitHub Apps and OAuth Apps provide scoped, installable integrations with their own permissions and tokens. Build on gh or the API before hand-rolling HTTP when a task is already scriptable.

QQuestionWhat is the difference between a webhook and polling the API?
ASolution

A webhook is a push: GitHub sends an HTTP POST to your endpoint when an event occurs, giving real-time reactions without polling. Polling the API repeatedly wastes rate limit and adds latency. Use webhooks for event reactions and the API for on-demand queries/actions.

QQuestionREST versus GraphQL for the GitHub API?
ASolution

REST exposes resource-oriented endpoints, simple to call and cache. GraphQL lets the client request exactly the fields it needs in one round trip, avoiding over-fetching for complex queries. Both authenticate with a token or app installation; use GraphQL for deep nested reads, REST for simple single-resource operations.

The rest of the GitHub platform

You rarely need all of them; know that they exist so you reach for the platform’s tool instead of building your own.

QQuestionWhat are GitHub Pages and Gists used for?
ASolution

Pages hosts static sites directly from a repository (this notes site uses that path). Gists are shareable single- or multi-file snippets, with secret (unlisted) and public variants, useful for one-off examples and diffs.

QQuestionWhat does GitHub provide for security?
ASolution

Dependabot alerts and automated updates, secret scanning (with push protection), code scanning (CodeQL), security advisories, and branch protection rules. Together they catch vulnerable dependencies and accidentally committed secrets before they are exploited.

Team best practices

QQuestionHow should a team handle secrets in a Git repository?
ASolution

Never commit them: use .gitignore for local files, environment variables and repository/organization secrets for CI, and enable secret scanning with push protection. If a secret is committed, treat it as compromised immediately and rotate it — history rewriting alone does not undo exposure.

QQuestionWhy keep pull requests small, and how do you enforce quality?
ASolution

Small, single-concern PRs are reviewable, merge cleanly, and are easy to revert; huge PRs rot into conflicts and discourage real review. Enforce quality with branch protection (required reviews, passing CI, no force-push) and automation (formatters, linters, tests, type checks) in CI rather than relying on discipline.

Pitfalls

QQuestionSelf-check

What does the Git object model store, and what is a branch really? When do you use reset versus revert?

ASolution

Commit, tree, blob, and tag objects, content-addressed by SHA so identical content is stored once and history is tamper-evident; a branch is just a movable pointer to a commit, and HEAD points at the current branch. Use reset to move your local branch/undo unpushed commits (soft/mixed/hard), and revert to undo a published commit by adding an inverse commit that preserves history.