Git, GitHub and GitHub Pages
2026-11-16
The course book goes deeper on everything in this lecture. Read before or after class:
init, add, commit, push and pullgit status, git log, git diffOn your own this week
Work through this one-hour video alongside the book chapter
It covers today’s whole arc a second time, at a gentler pace
Open a terminal and run git --version.
A version number means you’re ready.
An error = install Git now, and keep up with the slides while it runs
xcode-select --install in the terminal does it toosudo apt-get install gitGit stamps every commit with an author, so tell it who you are
You only need to do this once per computer, and you can update later on
# Set your name and email
# use the SAME email as your GitHub account
git config --global user.name "Your Name"
git config --global user.email "your.email@example.com"
# Make every new repository start on a branch named 'main'
# (older Git versions default to 'master' - set this once and forget it)
git config --global init.defaultBranch main
# Check your settings
git config --listGo to github.com and click “Sign up”
Choose a username
professional and memorable; it becomes part of your public URL (username.github.io)
so think future_CV, not rat_farts_2000
Add your university email (you can add others later)
Verify your account from the email they send
Then apply for the GitHub Student Developer Pack:
script_final_v3_REALLY.R aroundGit workflow: working directory, staging area, local and remote repositories
Pushing needs more than your password - GitHub stopped accepting passwords from the command line in 2021, and the first git push is where everyone gets stuck.
We’ll all use the GitHub CLI (gh), the easiest route:
# 1. Install the CLI
brew install gh # macOS
winget install --id GitHub.cli # Windows
sudo apt-get install gh # Ubuntu / WSL
# (no package manager? installers for every OS at cli.github.com)
# 2. Log in - one time only
gh auth login
# gh now asks four questions in the terminal; pick these answers:
# "Where do you use GitHub?" answer: GitHub.com
# "Preferred protocol?" answer: HTTPS
# "Authenticate Git with credentials?" answer: Yes
# "How would you like to authenticate?" answer: Login with a web browser
#
# It then prints a one-time code: copy it, press Enter, and paste the
# code into the browser window that opens. That's the whole login.
# 3. Confirm it worked
gh auth status # "Logged in to github.com as USERNAME"Tip
Done once, done forever on this machine.
The alternatives - SSH keys (which also log you in to Talapas in Week 10) and credential managers - are in Ch. 19.
# 1. Make a project and put it under version control
mkdir ~/projects/git_practice && cd ~/projects/git_practice
git init # creates the hidden .git/ folder
git status # read what it says
# 2. Create a few files worth tracking
echo "# My first repository" > README.md
echo 'print("hello, git")' > analysis.py
echo "lab notes, day 1" > notes.txt# 3. Stage - three ways to say what goes into the commit
git add README.md # one file, by name
git add *.py # wildcard: every .py file
git add . # everything new or changed from here down
# 4. Commit the staged snapshot
git commit -m "First commit: README, analysis script, notes"
git status # "working tree clean" - everything is recordedstuff, final, final2, fixed it · Good: Normalize counts before PCAgit status and git diff before every commit - know exactly what you are recordinggit diff and commit hashes7d4e8c2”) and use it anywhere a command wants a commitHEAD~1 is one commit backFirst, make the repository’s empty home on GitHub - we’ll click through this together:
git_practiceNote
Why branch -M main? Older Git creates the first branch as master (harmless if yours is already main)
GitHub takes the first branch you push as the repository’s default, so push main first and the two sides agree.
pullYour repository now lives in two places - so finish the loop:
# 1. On github.com: open README.md, click the pencil icon,
# add a line, and commit the change THERE
# 2. Bring that commit down to your laptop
git pull
# 3. Proof - both commits, one history, each with its short hash
git log --oneline # e.g. f8c21aa Add line from the web
# 7d4e8c2 First commit: README, ...
# 4. And exactly what changed between any two commits, by their hashes:
git diff 7d4e8c2 f8c21aapush and pull are the same verb in opposite directions - this is also how you’ll move between laptop and Talapas in Week 10git pull → edit → git add . → git commit -m "..." → git pushTip
Lost or confused? git status always tells you the next command.
And worst case: your work is on GitHub - delete the folder and git clone it back.
.gitignore? Not everything belongs in history.DS_Store, .Rhistory), package caches.gitignore file: a list of patterns Git pretends not to seegit add .project/
├── README.md # Project description - the front page on GitHub
├── .gitignore # What Git should never track
├── data/ # Raw data (usually .gitignore'd - README says where it lives)
├── analysis/ # Analysis scripts (.R, .py, .sh, .qmd)
├── results/ # Output files (commit small tables/figures; regenerable ones can be ignored)
└── docs/ # Documentation, or the rendered website for Pages
environment.yml (next week) - small, human-readable, hard to recreate.quarto/From Quarto source to a live website
main, /docshttps://username.github.io/repo_nameoutput-dir: docs in _quarto.yml means quarto render fills docs/quarto publish gh-pages is the one-command alternative)In L07 you built example_website - a real four-page Quarto site (home, research, publications, CV) with your details in it
A website is just a folder of HTML files; GitHub Pages will serve that folder to the world.
Step one is getting the folder rendered and under version control:
cd ~/projects/my_website # your website project from last week
# 1. Render the site one final time
# _quarto.yml says output-dir: docs, so the finished HTML
# lands in docs/ - open docs/index.html to see what will go live
quarto render
touch docs/.nojekyll # tells GitHub Pages: serve the files as-is
# 2. Exactly the walkthrough from earlier - plus the .gitignore,
# so Quarto's working folder stays out of the repository
git init
echo ".quarto/" > .gitignore
git add .
git commit -m "First commit: my academic website"
git branch -M mainmain, /docs → Save - you are telling GitHub “serve the docs/ folder of main as a website”https://USERNAME.github.io/my_website - on your phone too; it is the public internet now.qmd → quarto render → git add . → git commit → git push - live about a minute laterTip
That URL is real, permanent, and free - put it in your email signature.
It is also the mechanism that your term project report will use.
quarto render → touch docs/.nojekyll → git init → commit - exactly today’s finale, on your own machineTip
The same publish loop ends HW2 (goes out today, due Monday, November 30: analysis → Quarto report → pushed to GitHub)
The same loop ends the term project too (due Friday, December 11, with a README like the example).
git add and git commitgit switch (and git restore, two slides on) are the modern commands that split the overloaded git checkout in two - older tutorials say checkout, and both forms work:
# 1. Start your day - update your local copy
git pull origin main
# 2. Create a feature branch
git switch -c new-feature
# 3. Make changes and commit regularly
git add .
git commit -m "Add new analysis function"
# 4. Push your branch
git push origin new-feature
# 5. Create pull request on GitHub (via website)git restore and resetting HEAD# Discard your edits to a file (back to the last commit) - GONE for good
git restore analysis.R
# Un-stage a file, keeping your edits
git restore --staged analysis.R
# Undo the last commit, three strengths:
git reset --soft HEAD~1 # undo commit, keep changes staged
git reset HEAD~1 # undo commit, keep changes unstaged
git reset --hard HEAD~1 # undo commit, DISCARD the changesWarning
restore (without --staged) and reset --hard delete real work with no confirmation. Run git status and git diff first, so you know exactly what you are throwing away. App. H has the full undo table.
The other way a repository reaches your laptop - someone else’s (or yours, on a new machine):
Keep going
(https://docs.github.com)(https://git-scm.com/book) (free online)(https://skills.github.com)(https://quarto.org/docs/publishing/github-pages.html)BioE Computational Tools 2026 - Knight Campus