Appendix E — Git and GitHub Command Reference
This appendix is a desk reference for authors maintaining Quarto publications. Git records snapshots of selected files; GitHub hosts repositories and provides collaboration and automation services. Neither replaces a backup or an institutional data governance policy. Practice unfamiliar commands in a disposable repository before using them on a manuscript.
E.1 E.1 Installation and identity
Install Git from https://git-scm.com/ and open a terminal. On Windows, Git Bash provides the shell syntax used in this appendix. PowerShell users should adapt shell commands such as mkdir and environment-variable assignments. Git commands themselves are generally portable.
git --version
git config --global user.name "Your Name"
git config --global user.email "YOUR_EMAIL"
git config --global init.defaultBranch main
git config --list --show-originThe name and email become commit metadata, not login credentials. Use a GitHub-provided no-reply address if appropriate. Omit --global to configure only the current repository. Do not publish configuration output containing private information.
E.2 E.2 Starting a repository
| Command | Purpose |
|---|---|
git init -b main |
Initialize an existing project folder |
git clone URL |
Obtain a local copy of a remote repository |
git status -sb |
Inspect branch and working tree |
git remote -v |
Inspect configured remote URLs |
git rev-parse --show-toplevel |
Locate repository root |
Choose either initialization or cloning, not both. If a GitHub repository already contains a README or license, clone it before copying manuscript files into it. Keep independent books in independent repositories unless a shared build is deliberately required.
E.3 E.3 The daily editing cycle
The working tree contains editable files. The index (staging area) records the content intended for the next commit. A commit is a snapshot with metadata and parent references. A remote repository is a separate copy of the history.
git status -sb
git diff
git add chapters/ch01.qmd
git diff --staged
git commit -m "Clarify definition of reproducibility"
git log -5 --onelineReview the staged diff even if the working-tree diff looked correct: a file may have changed again after staging. Prefer small commits with meaningful messages. A correction to an equation and a redesign of the entire website should normally be separate commits.
| Inspection command | Interpretation |
|---|---|
git diff |
Unstaged changes to tracked files |
git diff --staged |
Staged changes relative to HEAD |
git diff HEAD |
Staged and unstaged tracked changes |
git log --oneline --graph --all |
Commit graph |
git show HEAD |
Latest commit and its changes |
git log -- chapters/ch01.qmd |
History of one file |
Untracked files are not shown by ordinary git diff; inspect them separately before staging.
E.4 E.4 Ignore generated and confidential files
A typical source repository contains QMD files, approved datasets, scripts, bibliographies and styles. Rendered output can usually be regenerated. Use the companion .gitignore as a starting point, adapting it if the chosen deployment method intentionally tracks output. Quarto freeze artifacts may be intentionally tracked when the publishing workflow requires them.
/_book/
/.quarto/
/.venv/
.Rhistory
.RData
.env
.env.*
!.env.example
/private-data/
__pycache__/
Ignore rules do not remove already tracked files. To stop tracking a file while retaining the local copy, use git rm --cached PATH and commit the change. This does not erase historical copies. If a credential was committed, revoke or rotate it immediately and follow the hosting provider’s sensitive-data removal guidance. Never use identifiable clinical records in a public practice repository.
E.5 E.5 Branches and integration
A branch is a movable reference to a commit. Create a branch for a focused correction and keep the main branch suitable for review or publication.
git switch main
git switch -c fix/clinic-summary
# Edit the relevant source files and run checks.
git add chapters/ch08.qmd
git commit -m "Correct clinic summary"
git switch main
git merge fix/clinic-summaryIn a collaborative repository, push the feature branch and open a pull request instead of merging directly into a protected main branch. A fast-forward moves the branch pointer; a non-fast-forward merge may create a merge commit. Inspect the graph to understand which occurred.
E.6 E.6 Resolving a merge conflict
A conflict occurs when Git cannot combine changes automatically. For example, two authors may revise the same sentence to report different statistics. The correct resolution is not necessarily either author’s wording: verify the data and produce an accurate sentence.
<<<<<<< HEAD
The mean waiting time was 15 minutes.
=======
The mean waiting time was 16 minutes.
>>>>>>> fix/clinic-summary
For observations 10, 12, 15, 18 and 25, the mean is 16 and median is 15. Replace the entire conflict block with the verified statement. Then:
git status
git add chapters/ch08.qmd
git diff --staged
git merge --continueIf you cannot resolve the conflict, git merge --abort attempts to restore the pre-merge state. Start merges with a clean working tree to make recovery easier. The supplied practice script creates and resolves a genuine conflict in an isolated temporary repository.
E.7 E.7 Remote collaboration
git remote add origin https://github.com/OWNER/REPOSITORY.git
git push -u origin main
git fetch origin
git log --oneline HEAD..origin/main
git pull --ff-onlyReplace OWNER and REPOSITORY with actual values. The first push assumes a compatible empty remote and appropriate permissions. Fetch retrieves history without merging it into your branch. A fast-forward-only pull refuses to combine divergent histories, allowing you to review the divergence deliberately.
For a feature branch, use git push -u origin fix/clinic-summary. On GitHub, open a pull request targeting main, describe the purpose, include validation results, and request review. After merging, update local main and delete the local branch with git branch -d fix/clinic-summary if Git confirms it is merged. Squash merges may require separate inspection before deletion.
Use Git Credential Manager, GitHub CLI authentication, or SSH according to your institution’s policy. Never embed access tokens in remote URLs, scripts, or QMD files.
E.8 E.8 Recovering work safely
| Goal | Command | Caution |
|---|---|---|
| Unstage a file | git restore --staged PATH |
Keeps working-tree edits |
| Discard unstaged edits | git restore PATH |
Overwrites unstaged tracked content |
| Inspect an old file | git show COMMIT:PATH |
Read-only |
| Save an old version separately | git show COMMIT:PATH > recovered.qmd |
Choose a new filename |
| Reverse a shared commit | git revert COMMIT |
Creates a new commit |
| Find recent local references | git reflog |
Local history may expire |
| Preserve unfinished tracked work | git stash push -m "draft" |
Add -u for untracked files |
| Recover stashed work | git stash apply |
May conflict; retains stash |
Before any destructive operation, inspect status and save important changes. Avoid git reset --hard, git clean -fd, and force pushes in routine manuscript workflows. They can discard work or rewrite shared history. A reflog cannot recover every untracked file or guarantee indefinite recovery.
E.9 E.9 Editions and releases
git status -sb
git tag -a v1.0.0 -m "First reviewed edition"
git push origin v1.0.0
git show v1.0.0A tag identifies a source revision; a GitHub release can additionally include rendered PDF or EPUB artifacts and release notes. Record software versions and data provenance so the edition can be reconstructed. Do not move a published tag silently. Use a new patch version for corrections, for example v1.0.1. Version numbers are an editorial convention, not a guarantee of reproducibility.
E.10 E.10 Automated validation and publication
A continuous integration workflow can check code and render HTML on each proposed change. The companion workflow is a validation-only example; it does not publish or require deployment credentials. Copy it into .github/workflows/validate.yml at the root of the standalone practice repository.
Before adding automated publication, establish a successful clean build. For GitHub Pages, configure the repository’s Pages source to match the selected deployment method. For Cloudflare Pages, choose a Git-integrated build or direct upload as appropriate. Do not mix publishing strategies without understanding which branch or directory is authoritative. Chapter 15 discusses deployment in detail.
A green build indicates the configured checks passed, not that the manuscript is mathematically correct, accessible, or free of confidential information. Review those separately.
E.11 E.11 Troubleshooting quick reference
| Symptom | First action | Likely resolution |
|---|---|---|
| Not a git repository | git rev-parse --show-toplevel |
Navigate to correct folder or clone |
| Nothing to commit | git status -sb |
Check whether edits were saved or ignored |
| Push rejected (non-fast-forward) | git fetch origin |
Inspect divergence; integrate reviewed changes |
| Authentication failed | git remote -v |
Check URL, account and credential setup |
| Merge conflict | git status |
Resolve, stage, continue or abort |
| File unexpectedly ignored | git check-ignore -v PATH |
Review matching rule |
| Wrong branch | git branch --show-current |
Save edits before switching |
| Build fails remotely | Read workflow logs | Reproduce with matching dependencies |
| Site displays old edition | Check deployed commit and output path | Correct deployment source; inspect caching |
E.12 E.12 Guided practice
- Initialize a repository and configure a local practice identity.
- Commit a QMD file, edit it, and compare unstaged and staged differences.
- Create a feature branch and correct the waiting-time mean.
- Create a competing edit on main and resolve the resulting conflict using the data.
- Recover the first version into a separate file without changing history.
- Create a tag identifying the reviewed edition.
- Confirm that a dummy
.envfile is ignored without using any real credentials. - Explain why reverting a shared commit is usually preferable to resetting and force-pushing.
E.13 E.13 Applied project: a reproducible textbook release
Create a small Quarto book with a mathematical example, independent R and Python verification scripts, and a documented revision history. Use synthetic data. Demonstrate a feature branch, a reviewed correction, a release tag, and a validation workflow. Submit the source archive, commit graph, numerical checks, and a short reflection on recovery and privacy. Remote publishing is optional unless an instructor explicitly requires it.
| Criterion | Points |
|---|---|
| Repository organization and safe ignore rules | 5 |
| Meaningful commits and branch workflow | 5 |
| Mathematical accuracy and validation | 5 |
| Recovery demonstration and release tag | 5 |
| Documentation and privacy review | 5 |
| Total | 25 |