← All guides

Programmer’s Reference

Git / GitHub

Inspect changes, make focused commits, and use branches and pull requests.

Git commands run inside a repository. GitHub CLI examples require gh and an already authenticated account. Never commit secrets.

8 entries · Essentials first · Reviewed October 5, 2026

Glossary: commands, keywords & terms

Select a term for its definition, syntax, example, and common mistakes.

Essentials

status, diff, and log

Inspect working-tree changes, staged changes, and recent history.

Terminal
git status --short
git diff
git diff --cached
git log -5 --oneline

Practical useReview a proposed application fix before creating a release.

Common mistakesUntracked file contents do not appear in git diff. Review files before staging; diffs can contain private data.

Source: git-scm.com documentation (1) · git-scm.com documentation (2) · git-scm.com documentation (3)

Stage selected files and commit

Stage named files, review exactly what is staged, and save a commit.

Terminal
git add -- demo.html demo.css
git diff --cached
git commit -m 'Improve demo reference navigation'

Practical useCreate a focused website change after testing.

Common mistakesAvoid git add . when unrelated changes or secrets may exist. A commit does not push or deploy anything.

Source: git-scm.com documentation (1) · git-scm.com documentation (2)

Repository hygiene

Keep local files out of Git

Define example ignore rules in .gitignore.

Git configuration
.env
.venv/
node_modules/
*.log

Practical useKeep local tooling and private environment files out of an application checkout.

Common mistakesIgnoring does not remove already tracked files or purge leaked secrets from history. Rotate exposed credentials through the proper process.

Source: git-scm.com documentation

Collaboration

fetch and fast-forward pull

Refresh remote-tracking refs, then update the current branch only if a fast-forward is possible.

⚠ Caution: Pull changes checkout files and may affect a running app if it uses that checkout.

Terminal
git fetch origin
git pull --ff-only

Practical useBring a clean staging checkout up to date.

Common mistakespull changes working files. Check the branch and status first; a diverged branch requires a deliberate merge or rebase.

Source: git-scm.com documentation (1) · git-scm.com documentation (2)

Push a topic branch

Publish a named demo branch and configure its upstream.

⚠ Caution: Publishes repository content and may trigger automation.

Terminal
git push -u origin demo/reference-update

Practical usePublish reviewed demo work through the established release process.

Common mistakesConfirm the remote and branch. A push may trigger CI or deployment; do not use force unless its impact is understood.

Source: git-scm.com documentation

Open a draft pull request

Use GitHub CLI to propose a pushed branch for review as a draft.

⚠ Caution: Publishes a pull request to the selected repository.

Terminal
gh pr create --draft --base main --head demo/reference-update --title 'Improve demo reference' --body 'Adds tested navigation for the demo reference.'

Practical useUse a draft review for a proposed project change.

Common mistakesConfirm the actual default branch, repository, and visibility. This sends the title/body to GitHub; a draft is not a merge.

Source: cli.github.com documentation

Undo and recovery

Revert versus restore

Revert makes a new commit that undoes an existing commit. restore replaces uncommitted file contents. These are separate alternatives.

⚠ Caution: restore discards local edits; revert changes repository content and may affect future deployments.

Terminal
git log -5 --oneline
# Replace EXAMPLE_COMMIT with a reviewed real commit ID:
# git revert EXAMPLE_COMMIT
# Discard changes only after backing them up:
# git restore -- demo.html

Practical useRecover a reviewed demo change with history preserved.

Common mistakesDo not blindly reset --hard or clean -fd. restore can lose uncommitted work; revert may conflict and still needs testing.

Source: git-scm.com documentation (1) · git-scm.com documentation (2)

Back to top ↑