{ "cells": [ { "cell_type": "markdown", "id": "lab04-00", "metadata": {}, "source": [ "# Lab 04: Git and GitHub\n", "\n", "**Leave with a repository for your homework.**\n", "\n", "1. Fork the course repository.\n", "2. Make changes on branches. Review and merge them.\n", "3. Bring in course updates. Keep using your fork for homework.\n", "\n", "**Open beside this page:**\n", "\n", "- [GitHub](https://github.com).\n", "- A **DataHub terminal**: **File → New → Terminal** in JupyterLab.\n", "- A local Bash terminal works too; use Git Bash on Windows.\n", "\n", "Run commands in the **terminal, not Python cells**. No Python kernel needed.\n", "\n", "- Diagrams showing as source? Use the course page.\n", "- The merge-conflict exercise at the end is optional.\n" ] }, { "cell_type": "markdown", "id": "lab04-01", "metadata": {}, "source": [ "## What is Git for?\n", "\n", "**Git is version control. It keeps your code's history.**\n", "\n", "In Lab 03, we saved the seed and inputs. We need the code that used them too.\n", "\n", "- **Commit:** a snapshot you choose to record, with a message, author, and links to earlier commits.\n", "- **Compare:** see what changed and where a problem started.\n", "- **Recover:** get back to work you've committed.\n", "- **Branch and merge:** try changes separately, then combine them.\n", "- **Work offline:** a normal clone includes the files and history. Git is *distributed*.\n", "\n", "Keep one project with a history, instead of `simulation_final.py`,\n", "`simulation_final2.py`, and `simulation_really_final.py`.\n", "\n", "- For a result, record **commit + seed + inputs + environment**.\n", "- **Save, commit, and push are separate steps.**\n", "- Still check the physics. Git doesn't tell us whether the calculation is right.\n", "\n", "[More: What is Git?](https://git-scm.com/book/en/v2/Getting-Started-What-is-Git%3F)\n" ] }, { "cell_type": "markdown", "id": "lab04-02", "metadata": {}, "source": [ "### What does GitHub add?\n", "\n", "**GitHub hosts Git repositories online.** Git works without it.\n", "\n", "| Git | GitHub |\n", "| --- | --- |\n", "| Keeps commits and branches | Hosts the code and history |\n", "| Compares and combines changes | Adds sharing, permissions, and review |\n", "| Works locally, including offline | Lets others access the work online |\n", "\n", "- **Pull requests:** propose and review changes.\n", "- **Issues:** track problems and work to do.\n", "- **Forks:** make your own repository from someone else's; contribute back if you want.\n", "- **Actions:** run automated checks.\n", "\n", "Here, **local** means the machine running Git: DataHub or your laptop.\n", "DataHub runs on a server; GitHub holds another copy.\n", "\n", "You committed offline. Can your partner see it on GitHub yet?\n", "\n", "[Browser walkthrough: GitHub Hello World](https://docs.github.com/en/get-started/using-github/hello-world)\n" ] }, { "cell_type": "markdown", "id": "lab04-03", "metadata": {}, "source": [ "### Where is the change right now?\n", "\n", "**Edit. Stage. Commit. Push.**\n", "\n", "| Place | What's there? |\n", "| --- | --- |\n", "| Working tree | The files you're editing |\n", "| Staging area | Content selected for the next commit |\n", "| Local repository | Committed history, stored in `.git` |\n", "| Remote | Another repository, reached through a saved URL |\n", "\n", "```mermaid\n", "%%{init: {\"theme\":\"base\",\"themeVariables\":{\"fontSize\":\"16px\",\"primaryColor\":\"#eff6ff\",\"primaryTextColor\":\"#0f172a\",\"primaryBorderColor\":\"#2563eb\",\"lineColor\":\"#718096\",\"textColor\":\"#0f172a\",\"edgeLabelBackground\":\"#f1f5f9\",\"clusterBkg\":\"#f8fafc\",\"clusterBorder\":\"#64748b\",\"titleColor\":\"#0f172a\"},\"flowchart\":{\"htmlLabels\":true,\"curve\":\"linear\",\"nodeSpacing\":32,\"rankSpacing\":48},\"fontFamily\":\"Arial\"}}%%\n", "flowchart TB\n", " subgraph local[Local: DataHub or laptop]\n", " W[Working files] -->|git add| S[Staging area]\n", " S -->|git commit| C[Local branch and committed history]\n", " T[Remote-tracking refs: origin/main] -->|git merge origin/main| C\n", " C -->|switch or completed merge updates files| W\n", " end\n", " C -->|git push| R[GitHub repository]\n", " R -->|git fetch| T\n", " class W main\n", " class S feature\n", " class C merged\n", " class R remote\n", " class T main\n", " style local fill:#f8fafc,stroke:#64748b,color:#0f172a\n", "\n", " classDef default fill:#f8fafc,stroke:#64748b,color:#0f172a,stroke-width:2px\n", " classDef main fill:#dbeafe,stroke:#2563eb,color:#172554,stroke-width:2px\n", " classDef feature fill:#fef3c7,stroke:#b45309,color:#451a03,stroke-width:2px\n", " classDef merged fill:#ccfbf1,stroke:#0f766e,color:#134e4a,stroke-width:3px\n", " classDef remote fill:#ede9fe,stroke:#7c3aed,color:#2e1065,stroke-width:2px\n", " classDef other fill:#ffe4e6,stroke:#be123c,color:#4c0519,stroke-width:2px\n", " linkStyle default stroke:#718096,stroke-width:2px\n", "```\n", "\n", "- **`add`:** stage content.\n", "- **`commit`:** record it locally.\n", "- **`push`:** send commits to the remote.\n", "- **`fetch`:** download history; update our record of remote branches. Working files stay put.\n", "- **`merge`:** combine that history with our current branch.\n", "- **`pull`:** fetch and integrate. We'll use `pull --ff-only` when no merge commit is needed.\n", "\n", "After `add`, where is the change? After `commit`? Has either sent it to GitHub?\n" ] }, { "cell_type": "markdown", "id": "lab04-19", "metadata": {}, "source": [ "## Forks: your copy of the course repository\n", "\n", "**A fork is another repository. A branch lives inside one.**\n", "\n", "- We'll fork [jmduarte/phys142](https://github.com/jmduarte/phys142) into your GitHub account.\n", "- Your fork starts with the course history. You control it; GitHub keeps the connection.\n", "- Your commits don't change the course repo. Course updates don't appear in your fork automatically.\n", "\n", "| Operation | What it creates or does |\n", "| --- | --- |\n", "| Branch | A name for a line of commits in one repository |\n", "| Fork | Another GitHub repository, with its own branches and permissions |\n", "| Clone | Local files and repository history |\n", "| Pull request | Proposes a merge within a repo or across forks |\n", "\n", "```mermaid\n", "%%{init: {\"theme\":\"base\",\"themeVariables\":{\"fontSize\":\"16px\",\"primaryColor\":\"#eff6ff\",\"primaryTextColor\":\"#0f172a\",\"primaryBorderColor\":\"#2563eb\",\"lineColor\":\"#718096\",\"textColor\":\"#0f172a\",\"edgeLabelBackground\":\"#f1f5f9\",\"clusterBkg\":\"#f8fafc\",\"clusterBorder\":\"#64748b\",\"titleColor\":\"#0f172a\"},\"flowchart\":{\"htmlLabels\":true,\"curve\":\"linear\",\"nodeSpacing\":32,\"rankSpacing\":48},\"fontFamily\":\"Arial\"}}%%\n", "flowchart TB\n", " accTitle: The course repository, your fork, and your clone\n", " accDescr: Fork the course repository on GitHub, clone your fork, and push your own commits to it. Fetch and merge upstream updates into your local branch, then push to your fork.\n", " U[\"Course repository: jmduarte/phys142\"]\n", " F[\"Your GitHub fork: origin\"]\n", " L[\"Your local clone on DataHub\"]\n", " U -->|Fork once on GitHub| F\n", " F -->|git clone| L\n", " F -->|git fetch origin| L\n", " L -->|git push origin| F\n", " U -->|git fetch upstream| L\n", " class U main\n", " class F feature\n", " class L merged\n", " classDef default fill:#f8fafc,stroke:#64748b,color:#0f172a,stroke-width:2px\n", " classDef main fill:#dbeafe,stroke:#2563eb,color:#172554,stroke-width:2px\n", " classDef feature fill:#fef3c7,stroke:#b45309,color:#451a03,stroke-width:2px\n", " classDef merged fill:#ccfbf1,stroke:#0f766e,color:#134e4a,stroke-width:3px\n", " classDef remote fill:#ede9fe,stroke:#7c3aed,color:#2e1065,stroke-width:2px\n", " classDef other fill:#ffe4e6,stroke:#be123c,color:#4c0519,stroke-width:2px\n", " linkStyle default stroke:#718096,stroke-width:2px\n", "```\n", "\n", "- **`origin` → your fork.** Push your commits here.\n", "- **`upstream` → the course.** Fetch updates here, then merge them locally.\n", "- These are remote names. Adding one doesn't give you push access.\n", "\n", "[More: GitHub forks](https://docs.github.com/en/pull-requests/reference/forks)\n" ] }, { "cell_type": "markdown", "id": "lab04-04", "metadata": {}, "source": [ "## Fork the course repository\n", "\n", "**Make your copy. Use it for the rest of the course.**\n", "\n", "1. Sign in and open [jmduarte/phys142](https://github.com/jmduarte/phys142).\n", "2. Choose **Fork**. Owner: **your account**. Name: **`phys142`**. Copy only **`main`**.\n", "3. Create the fork. Check its URL: `https://github.com/YOUR-USERNAME/phys142`.\n", "4. Find **forked from jmduarte/phys142** below the name.\n", "5. Leave **Actions disabled**. We don't need the website deployment workflow.\n", "\n", "- Already have this fork or a `homework/` directory? Look at it with me before repeating setup.\n", "- Your fork is public. You can look at each other's repositories.\n", "- **`assignments/private` is a separate staff submodule. Don't initialize it or copy its contents.**\n", "- Your files go under **`homework/`**. Leave course files in place.\n", "- Submit **code and a report on Gradescope**. Pushing doesn't submit homework.\n", "\n", "Find the **owner, repo name, branch, and latest commit**. Check the URL:\n", "the README and its links still describe the course, even in your fork.\n" ] }, { "cell_type": "markdown", "id": "lab04-05", "metadata": {}, "source": [ "### Make a branch for your homework setup\n", "\n", "**Both branches start at the same commit.**\n", "\n", "1. In **your fork**, create **`homework-setup`** from `main` using the branch selector.\n", "2. On that branch, choose **Add file → Create new file**.\n", "3. Name it **`homework/README.md`**. GitHub creates the directory from the path.\n", "4. Add:\n", "\n", "```text\n", "# My PHYS 142 homework\n", "\n", "My code, reports, and notes for PHYS 142 go here.\n", "Record how to run each calculation, including its seed and inputs.\n", "```\n", "\n", "5. Choose **Commit changes**. Message: **`Add my homework README`**.\n", "6. Commit to **`homework-setup`**.\n", "\n", "- A branch is a **name pointing to a commit**, not another directory.\n", "- This commit moves `homework-setup`; `main` stays put.\n", "- Use messages that tell us what changed. `stuff` won't help later.\n", "\n", "Switch to `main`: is the file there? Switch back and find your commit.\n" ] }, { "cell_type": "markdown", "id": "lab04-06", "metadata": {}, "source": [ "### Open a pull request and merge it\n", "\n", "**Check the destination. Read the diff.**\n", "\n", "Open a PR with these settings:\n", "\n", "| Field | Choose |\n", "| --- | --- |\n", "| Base repository — receives the change | **`YOUR-USERNAME/phys142`** |\n", "| Base branch | **`main`** |\n", "| Head repository — supplies the change | **`YOUR-USERNAME/phys142`** |\n", "| Compare branch | **`homework-setup`** |\n", "\n", "GitHub may suggest the course repo as the base. **Change it to your fork.**\n", "\n", "1. Add a title and a sentence explaining the homework directory.\n", "2. Read **Files changed** with a partner. This is the **diff**.\n", "3. Choose **Create a merge commit** and confirm. Use this option to match the diagram.\n", "\n", "```mermaid\n", "%%{init: {\"theme\":\"base\",\"themeVariables\":{\"fontSize\":\"16px\",\"primaryColor\":\"#eff6ff\",\"primaryTextColor\":\"#0f172a\",\"primaryBorderColor\":\"#2563eb\",\"lineColor\":\"#718096\",\"textColor\":\"#0f172a\",\"edgeLabelBackground\":\"#f1f5f9\",\"clusterBkg\":\"#f8fafc\",\"clusterBorder\":\"#64748b\",\"titleColor\":\"#0f172a\"},\"flowchart\":{\"htmlLabels\":true,\"curve\":\"linear\",\"nodeSpacing\":32,\"rankSpacing\":48},\"fontFamily\":\"Arial\"}}%%\n", "flowchart LR\n", " accTitle: Branching and merging a README change\n", " accDescr: Solid arrows follow development from A to B and M. M joins A and B. Dotted arrows show branch pointers. Git stores parent references backward.\n", " A((\"A: Course version\")) --> M(((\"M: Reviewed change\")))\n", " A --> B((\"B: Homework README\"))\n", " B --> M\n", " PM[main] -. points to .-> M\n", " PF[homework-setup] -. points to .-> B\n", " class A,PM main\n", " class B,PF feature\n", " class M merged\n", " classDef default fill:#f8fafc,stroke:#64748b,color:#0f172a,stroke-width:2px\n", " classDef main fill:#dbeafe,stroke:#2563eb,color:#172554,stroke-width:2px\n", " classDef feature fill:#fef3c7,stroke:#b45309,color:#451a03,stroke-width:2px\n", " classDef merged fill:#ccfbf1,stroke:#0f766e,color:#134e4a,stroke-width:3px\n", " classDef remote fill:#ede9fe,stroke:#7c3aed,color:#2e1065,stroke-width:2px\n", " classDef other fill:#ffe4e6,stroke:#be123c,color:#4c0519,stroke-width:2px\n", " linkStyle default stroke:#718096,stroke-width:2px\n", "```\n", "\n", "- Each circle is a commit. Time runs left to right; earlier course history is omitted.\n", "- `M` joins both histories. Git stores links back to its **two parents**.\n", "- Deleting a merged branch name leaves its commits in `main`'s history.\n", "- Opening the PR doesn't change `main`. Merging does.\n", "\n", "Check **your fork's `main`** for `homework/README.md` and find the merged PR.\n", "The course repo hasn't changed.\n", "\n", "| Similar names | Different jobs |\n", "| --- | --- |\n", "| Pull request | Propose and review a merge on GitHub |\n", "| `git pull` | Update the local checkout |\n", "\n", "[More: pull requests](https://docs.github.com/en/pull-requests/reference/pull-requests)\n" ] }, { "cell_type": "markdown", "id": "lab04-16", "metadata": {}, "source": [ "## Set up SSH before cloning your fork\n", "\n", "### Create an SSH key\n", "\n", "**Your public key goes on GitHub. Your private key stays here.**\n", "\n", "Run this on **the machine where you run Git**: DataHub for this lab.\n", "\n", "```bash\n", "mkdir -p ~/.ssh\n", "chmod 700 ~/.ssh\n", "ls -la ~/.ssh\n", "```\n", "\n", "- Already see `id_ed25519_phys142` or `id_ed25519_phys142.pub`? **Don't overwrite them. Ask me.**\n", "- Otherwise, replace `YOUR-GITHUB-EMAIL` below and create the key:\n", "\n", "```bash\n", "ssh-keygen -t ed25519 -C \"YOUR-GITHUB-EMAIL\" -f ~/.ssh/id_ed25519_phys142\n", "```\n", "\n", "- Enter a **passphrase** at the prompts. It protects the private key; it isn't your GitHub password.\n", "- **`id_ed25519_phys142`** is private. Don't share it or put it in a repo.\n", "- **`id_ed25519_phys142.pub`** is public. That's the one we'll copy to GitHub.\n", "\n", "Load the key into an agent in this terminal:\n", "\n", "```bash\n", "eval \"$(ssh-agent -s)\"\n", "ssh-add ~/.ssh/id_ed25519_phys142\n", "ssh-add -l\n", "```\n", "\n", "- `ssh-add` asks for the key's passphrase. `ssh-add -l` should list the key.\n", "- After a new terminal or DataHub restart, rerun the agent block. **Don't generate another key.**\n", "\n", "[More: SSH keys and the agent](https://docs.github.com/en/authentication/connecting-to-github-with-ssh/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent)\n" ] }, { "cell_type": "markdown", "id": "lab04-16-register", "metadata": {}, "source": [ "### Add the public key to GitHub\n", "\n", "```bash\n", "cat ~/.ssh/id_ed25519_phys142.pub\n", "```\n", "\n", "1. Copy the **whole line**, starting with `ssh-ed25519`.\n", "2. Open GitHub **Settings → SSH and GPG keys → New SSH key**.\n", "3. Title: **PHYS 142 DataHub**. Key type: **Authentication Key**.\n", "4. Paste the **public key** and choose **Add SSH key**.\n", "\n", "Test the connection using this key:\n", "\n", "```bash\n", "ssh -T -i ~/.ssh/id_ed25519_phys142 -o IdentitiesOnly=yes git@github.com\n", "```\n", "\n", "- First connection? Compare the displayed fingerprint with [GitHub's published fingerprints](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/githubs-ssh-key-fingerprints). Type `yes` only if it matches.\n", "- The greeting must name **your GitHub account**. If it names someone else or says `Permission denied`, stop and ask me.\n", "- **Successfully authenticated** plus **does not provide shell access** is success. GitHub accepts Git operations, not an interactive shell; this test normally exits with status `1`.\n", "- `git@github.com` always uses the SSH user **`git`**. The key identifies your GitHub account.\n", "\n", "[Add a key](https://docs.github.com/en/authentication/connecting-to-github-with-ssh/adding-a-new-ssh-key-to-your-github-account) · [Test the connection](https://docs.github.com/en/authentication/connecting-to-github-with-ssh/testing-your-ssh-connection)\n" ] }, { "cell_type": "markdown", "id": "lab04-07", "metadata": {}, "source": [ "## Get a local copy of your fork\n", "\n", "**Make a separate clone for your homework.**\n", "\n", "- Keep the course copy opened by DataHub as your reference. Leave its remotes alone.\n", "- All Git exercises below happen in **`~/phys142-lab04/phys142`**, your own clone.\n", "\n", "- Replace **`YOUR-USERNAME`** with your GitHub username.\n", "- Run this block once. It creates `~/phys142-lab04/phys142`.\n", "- Already have `phys142-lab04`? Look inside it with me before continuing.\n", "- If `git --version` fails on DataHub, ask me.\n", "\n", "```bash\n", "git --version\n", "cd ~\n", "mkdir phys142-lab04\n", "cd phys142-lab04\n", "git clone --config core.sshCommand=\"ssh -i ~/.ssh/id_ed25519_phys142 -o IdentitiesOnly=yes\" \\\n", " git@github.com:YOUR-USERNAME/phys142.git\n", "cd phys142\n", "git remote add upstream https://github.com/jmduarte/phys142.git\n", "pwd\n", "git status\n", "git remote -v\n", "```\n", "\n", "Check the URLs:\n", "\n", "| Remote | Repository | We'll use it to… |\n", "| --- | --- | --- |\n", "| `origin` | **`YOUR-USERNAME/phys142`** (SSH) | Fetch and push your work |\n", "| `upstream` | **`jmduarte/phys142`** (HTTPS) | Fetch course updates |\n", "\n", "- `origin` uses SSH and the key you just registered. Enter its passphrase if prompted.\n", "- `--config core.sshCommand=...` selects that key for **this new clone only**.\n", "- `upstream` uses HTTPS to read the public course repo.\n", "- `clone` gives us the files and `.git` history. No `git init` needed.\n", "- Use the **plain clone** above: no `--recurse-submodules` or submodule initialization.\n", "- Leave **`assignments/private` uninitialized**. Forking doesn't grant access to it.\n" ] }, { "cell_type": "markdown", "id": "lab04-08", "metadata": {}, "source": [ "### Set your name and email\n", "\n", "**These identify your commits. They don't log you in.**\n", "\n", "Replace both placeholders. For email privacy, copy your exact GitHub\n", "**noreply address** from [email settings](https://github.com/settings/emails).\n", "\n", "```bash\n", "git config user.name \"Your Name\"\n", "git config user.email \"YOUR-EXACT-GITHUB-NOREPLY-ADDRESS\"\n", "git log --oneline --graph --all --decorate -6\n", "```\n", "\n", "- No `--global`: these settings apply only to this repo.\n", "- They set the commit author. They don't grant push access.\n", "- The short strings are **commit IDs**. Shared course commits have the same IDs in everyone's fork.\n", "- Your new commits will usually have different IDs from your partner's.\n", "- Scrolling viewer? **Space** moves down; **q** returns to the prompt.\n" ] }, { "cell_type": "markdown", "id": "lab04-09", "metadata": {}, "source": [ "### Add a small practice calculation to your workspace\n", "\n", "- **Small text files are easy to compare.**\n", "- Stay in `~/phys142-lab04/phys142`.\n", "- Practice with die-simulation inputs. We'll edit them, not run the simulation.\n", "- Paste each whole block, including `EOF`. `cat > filename` writes that text to a file.\n", "- Create the files under `homework/`. Keep the course's root README and `.gitignore` in place.\n", "\n", "```bash\n", "mkdir homework/practice\n", "cat > homework/practice/settings.txt <<'EOF'\n", "distribution = fair_die\n", "seed = 20261008\n", "samples = 100\n", "EOF\n", "```\n", "\n", "```bash\n", "cat > homework/.gitignore <<'EOF'\n", ".ipynb_checkpoints/\n", "__pycache__/\n", "*.pyc\n", ".venv/\n", ".env\n", "results/\n", "EOF\n", "git status\n", "```\n", "\n", "- **`.gitignore`:** skip untracked checkpoints, caches, environments, and generated results.\n", "- These rules apply under `homework/`, alongside the course's existing rules.\n", "- It doesn't untrack committed files or remove them from earlier commits.\n", "- Keep code, small inputs, README instructions, and environment specifications in the repository.\n", "- Leave large generated datasets and credentials out. Ignoring a file can't protect a secret you've already shared.\n", "\n", "Git's [ignore rules](https://git-scm.com/docs/gitignore).\n" ] }, { "cell_type": "markdown", "id": "lab04-10", "metadata": {}, "source": [ "### Stage the files\n", "\n", "- **Look at what's going into the commit.**\n", "\n", "```bash\n", "git diff\n", "git add homework/practice/settings.txt homework/.gitignore\n", "git diff --staged\n", "git status\n", "```\n", "\n", "| Command | What we see |\n", "| --- | --- |\n", "| `git status` | New, untracked files and changes to tracked files |\n", "| `git diff` | Unstaged edits to tracked files; no contents of untracked files |\n", "| `git diff --staged` | The content selected for the next commit |\n", "\n", "- `git add` stages the content **when you run it**.\n", "- Edit the file again? Run `git add` again to include that edit too.\n" ] }, { "cell_type": "markdown", "id": "lab04-11", "metadata": {}, "source": [ "- **Commit what we staged.**\n", "\n", "```bash\n", "git commit -m \"Record dice simulation settings and ignore generated files\"\n", "git status\n", "git log --oneline -3\n", "```\n", "\n", "- The working tree should be **clean**: no changes waiting to be committed.\n", "- Check GitHub. `homework/practice/settings.txt` shouldn't be there yet; we've only committed locally.\n", "- A clean working tree doesn't tell us whether we've pushed our commits.\n" ] }, { "cell_type": "markdown", "id": "lab04-12", "metadata": {}, "source": [ "## Make a branch from the terminal\n", "\n", "- **Change the sample count on a new branch.**\n", "\n", "```bash\n", "git switch -c more-samples\n", "```\n", "\n", "1. Open `homework/practice/settings.txt` in JupyterLab's file browser or your editor.\n", "2. Change only `samples = 100` to `samples = 1000` and **save**.\n", "3. Return to the terminal:\n", "\n", "```bash\n", "git diff\n", "git add homework/practice/settings.txt\n", "git diff --staged\n", "git commit -m \"Increase dice sample count to 1000\"\n", "git branch\n", "```\n", "\n", "- `switch -c` creates the branch and switches to it.\n", "- The star in `git branch` marks our current branch.\n", "- **HEAD** usually points to that branch. This commit moved `more-samples` forward.\n" ] }, { "cell_type": "markdown", "id": "lab04-13", "metadata": {}, "source": [ "### Switch back to main\n", "\n", "- **Same directory. Different version of the file.**\n", "- **Save and close** `homework/practice/settings.txt` before switching. An old editor tab could overwrite the new version.\n", "\n", "```bash\n", "git switch main\n", "cat homework/practice/settings.txt\n", "```\n", "\n", "- On `main`, `samples` should be `100` again. Git updated the working file.\n", "- The version with 1000 samples is still on `more-samples`.\n", "- Let's make a different change on `main`:\n", "\n", "```bash\n", "cat > homework/practice/NOTES.md <<'EOF'\n", "Record the seed and sample count when comparing simulation runs.\n", "EOF\n", "git add homework/practice/NOTES.md\n", "git commit -m \"Add a reminder about reproducible comparisons\"\n", "```\n", "\n", "| Branch | New change |\n", "| --- | --- |\n", "| `main` | The note |\n", "| `more-samples` | The larger sample count |\n", "\n", "Neither branch has both changes yet.\n" ] }, { "cell_type": "markdown", "id": "lab04-14", "metadata": {}, "source": [ "### Merge the changes\n", "\n", "- **Merge into the branch you're on.**\n", "- We're on `main`. Bring in `more-samples`:\n", "\n", "```bash\n", "git status\n", "git merge --no-ff more-samples -m \"Merge the larger-sample experiment\"\n", "cat homework/practice/settings.txt\n", "cat homework/practice/NOTES.md\n", "git log --oneline --graph --all --decorate -8\n", "```\n", "\n", "```mermaid\n", "%%{init: {\"theme\":\"base\",\"themeVariables\":{\"fontSize\":\"16px\",\"primaryColor\":\"#eff6ff\",\"primaryTextColor\":\"#0f172a\",\"primaryBorderColor\":\"#2563eb\",\"lineColor\":\"#718096\",\"textColor\":\"#0f172a\",\"edgeLabelBackground\":\"#f1f5f9\",\"clusterBkg\":\"#f8fafc\",\"clusterBorder\":\"#64748b\",\"titleColor\":\"#0f172a\"},\"flowchart\":{\"htmlLabels\":true,\"curve\":\"linear\",\"nodeSpacing\":32,\"rankSpacing\":48},\"fontFamily\":\"Arial\"}}%%\n", "flowchart LR\n", " accTitle: Merge two lines of development\n", " accDescr: Solid arrows follow development from A to B and C, then M. M combines B and C. Dotted arrows show branch pointers.\n", " A((\"A: 100 samples\")) --> C((\"C: Add notes\"))\n", " C --> M(((\"M: Merge\")))\n", " A --> B((\"B: 1000 samples\"))\n", " B --> M\n", " PM[main] -. points to .-> M\n", " PF[more-samples] -. points to .-> B\n", " class A,C,PM main\n", " class B,PF feature\n", " class M merged\n", " classDef default fill:#f8fafc,stroke:#64748b,color:#0f172a,stroke-width:2px\n", " classDef main fill:#dbeafe,stroke:#2563eb,color:#172554,stroke-width:2px\n", " classDef feature fill:#fef3c7,stroke:#b45309,color:#451a03,stroke-width:2px\n", " classDef merged fill:#ccfbf1,stroke:#0f766e,color:#134e4a,stroke-width:3px\n", " classDef remote fill:#ede9fe,stroke:#7c3aed,color:#2e1065,stroke-width:2px\n", " classDef other fill:#ffe4e6,stroke:#be123c,color:#4c0519,stroke-width:2px\n", " linkStyle default stroke:#718096,stroke-width:2px\n", "```\n", "\n", "- The diagram starts at the settings commit. Earlier README history is omitted.\n", "- Different files changed, so Git could combine the edits.\n", "- Check `main`: do we have **both** the note and 1000 samples?\n", "- `--no-ff` requests a merge commit joining both histories. We need one anyway: both branches advanced.\n", "- A merge doesn't check the code. Inspect it and rerun the calculation or tests.\n" ] }, { "cell_type": "markdown", "id": "lab04-15", "metadata": {}, "source": [ "### When Git can fast-forward\n", "\n", "- **Move the branch name to a commit that already exists.**\n", "- Without the `homework/practice/NOTES.md` change, `main` would be an ancestor of `more-samples`.\n", "- Move `main` to `B` without a new commit: that's a **fast-forward**.\n", "\n", "```mermaid\n", "%%{init: {\"theme\":\"base\",\"themeVariables\":{\"fontSize\":\"16px\",\"primaryColor\":\"#eff6ff\",\"primaryTextColor\":\"#0f172a\",\"primaryBorderColor\":\"#2563eb\",\"lineColor\":\"#718096\",\"textColor\":\"#0f172a\",\"edgeLabelBackground\":\"#f1f5f9\",\"clusterBkg\":\"#f8fafc\",\"clusterBorder\":\"#64748b\",\"titleColor\":\"#0f172a\"},\"flowchart\":{\"htmlLabels\":true,\"curve\":\"linear\",\"nodeSpacing\":32,\"rankSpacing\":48},\"fontFamily\":\"Arial\"}}%%\n", "flowchart LR\n", " subgraph before[Before fast-forward]\n", " A1[A] --> B1[B]\n", " M1[main] -. points to .-> A1\n", " F1[more-samples] -. points to .-> B1\n", " end\n", " subgraph after[After fast-forward]\n", " A2[A] --> B2[B]\n", " M2[main] -. points to .-> B2\n", " F2[more-samples] -. points to .-> B2\n", " end\n", " before ~~~ after\n", " class A1,B1,A2,B2 main\n", " class M1,M2 main\n", " class F1,F2 feature\n", " style before fill:#f8fafc,stroke:#64748b,color:#0f172a\n", " style after fill:#f8fafc,stroke:#64748b,color:#0f172a\n", "\n", " classDef default fill:#f8fafc,stroke:#64748b,color:#0f172a,stroke-width:2px\n", " classDef main fill:#dbeafe,stroke:#2563eb,color:#172554,stroke-width:2px\n", " classDef feature fill:#fef3c7,stroke:#b45309,color:#451a03,stroke-width:2px\n", " classDef merged fill:#ccfbf1,stroke:#0f766e,color:#134e4a,stroke-width:3px\n", " classDef remote fill:#ede9fe,stroke:#7c3aed,color:#2e1065,stroke-width:2px\n", " classDef other fill:#ffe4e6,stroke:#be123c,color:#4c0519,stroke-width:2px\n", " linkStyle default stroke:#718096,stroke-width:2px\n", " linkStyle 6 stroke:transparent,stroke-width:0px\n", "```\n", "\n", "- **Solid arrows:** order of commits.\n", "- **Dotted arrows:** which commit each branch points to.\n", "- Our actual example had two lines of development. It needed a two-parent merge.\n", "\n", "[Pro Git: branching and merging](https://git-scm.com/book/en/v2/Git-Branching-Basic-Branching-and-Merging).\n" ] }, { "cell_type": "markdown", "id": "lab04-17", "metadata": {}, "source": [ "## Push your work and bring updates back\n", "\n", "### Upload the committed history\n", "\n", "- **Push. Then check GitHub.**\n", "- Run the first two commands. Check **your fork's URL** and **`main`** before pushing.\n", "\n", "```bash\n", "git remote -v\n", "git branch --show-current\n", "git push origin main\n", "git rev-parse --short HEAD\n", "git status\n", "```\n", "\n", "- We've pushed `main` and its history, including the merged work.\n", "- This doesn't push every local branch name.\n", "\n", "Refresh `main` on GitHub and check:\n", "\n", "1. `homework/practice/settings.txt` has 1000 samples.\n", "2. `homework/practice/NOTES.md` is there.\n", "3. The latest commit ID matches the local `HEAD` printed above.\n" ] }, { "cell_type": "markdown", "id": "lab04-18", "metadata": {}, "source": [ "### Make a remote change, then update the clone\n", "\n", "- **Change it on GitHub. Check your local copy.**\n", "\n", "1. On GitHub, open `homework/README.md` in **your fork**, on **`main`**.\n", "2. Add `Current practice sample count: 1000.` and commit directly to `main`.\n", "3. Our local copy is still on the earlier commit. Fetch and compare:\n", "\n", "```bash\n", "git status\n", "git fetch origin\n", "git log --oneline main..origin/main\n", "git diff main origin/main -- homework/README.md\n", "cat homework/README.md\n", "```\n", "\n", "- `origin/main` is our **local record** of the fork's branch after fetching. It doesn't watch GitHub for updates.\n", "- Log and diff show the new commit; `cat homework/README.md` still shows the old file.\n", "- Check that the working tree is **clean**, then bring the commit into our `main`:\n", "\n", "```bash\n", "git merge --ff-only origin/main\n", "cat homework/README.md\n", "git status\n", "```\n", "\n", "- Next time: `git pull --ff-only origin main` combines fetch and fast-forward.\n", "- No second commit needed. We brought in the existing one.\n", "- `--ff-only` stops if the local and remote histories have diverged.\n", "- If it stops, run `git log --oneline --graph --all --decorate` and show me. We'll look at the histories before combining them.\n", "- Don't force-push or discard local work to get past the error.\n", "\n", "[Git pull](https://git-scm.com/docs/git-pull).\n" ] }, { "cell_type": "markdown", "id": "lab04-20", "metadata": {}, "source": [ "## Bring in updates from the course\n", "\n", "**Fetch from the course. Merge locally. Push to your fork.**\n", "\n", "New material appears in `jmduarte/phys142`. Your fork doesn't update itself.\n", "\n", "1. Work in `~/phys142-lab04/phys142`.\n", "2. Save your files. Check for a **clean working tree**; commit work you want to keep before switching or merging.\n", "3. Update from your fork, then check the course:\n", "\n", "```bash\n", "git status\n", "git switch main\n", "git pull --ff-only origin main\n", "git fetch upstream\n", "git log --oneline main..upstream/main\n", "```\n", "\n", "| Command | What it does |\n", "| --- | --- |\n", "| `pull --ff-only origin main` | Brings in changes from **your GitHub fork** |\n", "| `fetch upstream` | Downloads **course history**; leaves working files alone |\n", "| `log main..upstream/main` | Lists course commits your `main` doesn't have |\n", "\n", "`upstream/main` is our local record after the fetch. An empty log means no new course commits.\n", "\n", "4. Merge the course history into `main`, then push to your fork:\n", "\n", "```bash\n", "git merge --no-edit upstream/main\n", "git log --oneline --graph --all --decorate -10\n", "git push origin main\n", "git status\n", "```\n", "\n", "- **Already up to date?** Nothing new to merge. Repeat when new material is posted.\n", "- **Both sides have new commits?** Git may make a merge commit keeping both histories.\n", "- No `--ff-only` on this merge: your homework can make the histories diverge.\n", "- **`--no-edit`** accepts Git's generated merge message.\n", "- **Conflict?** Look at the files with me; the optional exercise below covers this. Don't force-push or discard work.\n", "\n", "**`origin` is your fork.** Pulling from it alone won't fetch course updates.\n", "After fetching `upstream`, you still need to **merge**, then **push**.\n", "\n", "[More: syncing a fork](https://docs.github.com/en/pull-requests/how-tos/work-with-forks/syncing-a-fork)\n" ] }, { "cell_type": "markdown", "id": "lab04-21", "metadata": {}, "source": [ "### Follow the two histories\n", "\n", "**Your homework stays. The course update comes in.**\n", "\n", "```mermaid\n", "%%{init: {\"theme\":\"base\",\"themeVariables\":{\"fontSize\":\"16px\",\"primaryColor\":\"#eff6ff\",\"primaryTextColor\":\"#0f172a\",\"primaryBorderColor\":\"#2563eb\",\"lineColor\":\"#718096\",\"textColor\":\"#0f172a\",\"edgeLabelBackground\":\"#f1f5f9\",\"clusterBkg\":\"#f8fafc\",\"clusterBorder\":\"#64748b\",\"titleColor\":\"#0f172a\"},\"flowchart\":{\"htmlLabels\":true,\"curve\":\"linear\",\"nodeSpacing\":32,\"rankSpacing\":48},\"fontFamily\":\"Arial\"}}%%\n", "flowchart LR\n", " accTitle: Merge a course update with your homework history\n", " accDescr: The course and your work share A. The course adds C and you add B. M in your local main merges both histories; pushing sends M to your fork. Upstream main stays at C.\n", " A((\"A: Shared start\")) --> C((\"C: Course update\"))\n", " A --> B((\"B: Your homework\"))\n", " C --> M(((\"M: Keep both\")))\n", " B --> M\n", " PU[upstream/main] -. points to .-> C\n", " PM[main after merge] -. points to .-> M\n", " class A,C,PU main\n", " class B feature\n", " class M,PM merged\n", " classDef default fill:#f8fafc,stroke:#64748b,color:#0f172a,stroke-width:2px\n", " classDef main fill:#dbeafe,stroke:#2563eb,color:#172554,stroke-width:2px\n", " classDef feature fill:#fef3c7,stroke:#b45309,color:#451a03,stroke-width:2px\n", " classDef merged fill:#ccfbf1,stroke:#0f766e,color:#134e4a,stroke-width:3px\n", " classDef remote fill:#ede9fe,stroke:#7c3aed,color:#2e1065,stroke-width:2px\n", " classDef other fill:#ffe4e6,stroke:#be123c,color:#4c0519,stroke-width:2px\n", " linkStyle default stroke:#718096,stroke-width:2px\n", "```\n", "\n", "- **`A`:** shared starting point.\n", "- **`B`:** your homework commit.\n", "- **`C`:** new course commit.\n", "- **`M`:** your local merge of both histories. Push it to **your fork**.\n", "- The course stays at **`C`**. Your homework hasn't been sent there.\n", "\n", "Solid arrows follow development; dotted arrows show branch pointers.\n", "No new course commit? No `C` or `M` yet.\n", "\n", "- Saving homework in your fork needs **no PR to the course**.\n", "- A course PR proposes a change to the **shared materials**. Check its base repository.\n", "\n", "Which remote gets your push? Which has course updates? How do fork, clone,\n", "and branch differ?\n" ] }, { "cell_type": "markdown", "id": "lab04-22", "metadata": {}, "source": [ "## Start your Assignment 1 directory\n", "\n", "**Set up the files you'll keep using.**\n", "\n", "| Directory | Contents |\n", "| --- | --- |\n", "| `assignments/` | Course handouts |\n", "| **`homework/assignment1/`** | Your code, report, and README |\n", "\n", "Start with a **clean working tree**. Make a branch and add the README:\n", "\n", "```bash\n", "git status\n", "git switch main\n", "git switch -c assignment1-setup\n", "mkdir homework/assignment1\n", "cat > homework/assignment1/README.md <<'EOF'\n", "# Assignment 1\n", "\n", "## Run my code\n", "TODO: Add the filenames, required packages, and exact command to run the calculation.\n", "\n", "## Reproduce a result\n", "TODO: Record the inputs, random seed, result, and uncertainty.\n", "\n", "## Check the calculation\n", "TODO: Describe a comparison or test and what it tells me.\n", "\n", "## Report\n", "TODO: Include the figures, explanations, and required AI-use appendix.\n", "EOF\n", "git add homework/assignment1/README.md\n", "git diff --staged\n", "git commit -m \"Start my Assignment 1 workspace\"\n", "git push -u origin assignment1-setup\n", "```\n", "\n", "On GitHub:\n", "\n", "1. Open a PR. **Base and head repositories: your fork.**\n", "2. **Base: `main`. Compare: `assignment1-setup`.**\n", "3. Read the diff. Choose **Create a merge commit**.\n", "4. Bring it back locally:\n", "\n", "```bash\n", "git switch main\n", "git pull --ff-only origin main\n", "git log --oneline -4\n", "git status\n", "```\n", "\n", "For your next homework session:\n", "\n", "- Check for course updates.\n", "- Branch for the change you're trying.\n", "- Add your source files and report. Replace the README's TODOs as you work.\n", "- Commit at useful stopping points; push what you want on GitHub.\n", "- For reported results, record **commit + inputs + seed + environment**.\n", "- **Submit code and report on Gradescope.** Saving and pushing don't submit them.\n" ] }, { "cell_type": "markdown", "id": "lab04-23", "metadata": {}, "source": [ "## Optional: make and resolve a merge conflict\n", "\n", "- A conflict can occur when two branches change the same line incompatibly.\n", "- Use two local branches. Leave `main` unchanged; don't push these branches.\n", "- Stay in `~/phys142-lab04/phys142`. Check that `git status` is **clean**.\n", "\n", "1. Create the first branch:\n", "\n", "```bash\n", "git switch main\n", "git switch -c seed-a\n", "```\n", "\n", "2. In `homework/practice/settings.txt`, replace `seed = 20261008` with `seed = 11`. Save, then:\n", "\n", "```bash\n", "git add homework/practice/settings.txt\n", "git commit -m \"Try seed 11\"\n", "git switch main\n", "git switch -c seed-b\n", "```\n", "\n", "3. `seed-b` starts from `main`, where the seed is still `20261008`. In the same file, replace it with `seed = 22`, save, then:\n", "\n", "```bash\n", "git add homework/practice/settings.txt\n", "git commit -m \"Try seed 22\"\n", "git merge seed-a\n", "```\n", "\n", "The merge should stop with a conflict in `homework/practice/settings.txt`: both branches changed the same seed. We must choose what to keep.\n" ] }, { "cell_type": "markdown", "id": "lab04-24", "metadata": {}, "source": [ "### Read the conflict before editing\n", "\n", "- Current branch: `seed-b`, seed `22`.\n", "- Incoming branch: `seed-a`, seed `11`.\n", "- No merge commit exists yet.\n", "\n", "```mermaid\n", "%%{init: {\"theme\":\"base\",\"themeVariables\":{\"fontSize\":\"16px\",\"primaryColor\":\"#eff6ff\",\"primaryTextColor\":\"#0f172a\",\"primaryBorderColor\":\"#2563eb\",\"lineColor\":\"#718096\",\"textColor\":\"#0f172a\",\"edgeLabelBackground\":\"#f1f5f9\",\"clusterBkg\":\"#f8fafc\",\"clusterBorder\":\"#64748b\",\"titleColor\":\"#0f172a\"},\"flowchart\":{\"htmlLabels\":true,\"curve\":\"linear\",\"nodeSpacing\":32,\"rankSpacing\":48},\"fontFamily\":\"Arial\"}}%%\n", "flowchart LR\n", " accTitle: Conflicting seed changes before the merge\n", " accDescr: Main stays at A. Seed-a points to B and seed-b to C. No merge commit exists yet. Solid arrows follow development; dotted arrows show branch pointers.\n", " A((\"A: Seed 20261008\")) --> B((\"B: Seed 11\"))\n", " A --> C((\"C: Seed 22\"))\n", " PM[main] -. points to .-> A\n", " PA[seed-a] -. points to .-> B\n", " PB[\"seed-b: Current branch\"] -. points to .-> C\n", " class A,PM main\n", " class B,PA feature\n", " class C,PB other\n", " classDef default fill:#f8fafc,stroke:#64748b,color:#0f172a,stroke-width:2px\n", " classDef main fill:#dbeafe,stroke:#2563eb,color:#172554,stroke-width:2px\n", " classDef feature fill:#fef3c7,stroke:#b45309,color:#451a03,stroke-width:2px\n", " classDef merged fill:#ccfbf1,stroke:#0f766e,color:#134e4a,stroke-width:3px\n", " classDef remote fill:#ede9fe,stroke:#7c3aed,color:#2e1065,stroke-width:2px\n", " classDef other fill:#ffe4e6,stroke:#be123c,color:#4c0519,stroke-width:2px\n", " linkStyle default stroke:#718096,stroke-width:2px\n", "```\n", "\n", "Run `git status` and open `homework/practice/settings.txt`. `HEAD` marks our side; `seed-a` marks the incoming side:\n", "\n", "```text\n", "<<<<<<< HEAD\n", "seed = 22\n", "=======\n", "seed = 11\n", ">>>>>>> seed-a\n", "```\n", "\n", "- Some configurations also show the original value in a `|||||||` block.\n", "- Choose one seed. Remove the conflict markers and the version you aren't keeping.\n" ] }, { "cell_type": "markdown", "id": "lab04-25", "metadata": {}, "source": [ "### Resolve, inspect, then commit\n", "\n", "Keep seed `11`. The complete file should be:\n", "\n", "```text\n", "distribution = fair_die\n", "seed = 11\n", "samples = 1000\n", "```\n", "\n", "Save, then inspect and commit:\n", "\n", "```bash\n", "git diff\n", "git add homework/practice/settings.txt\n", "git diff --staged\n", "git commit -m \"Resolve the seed conflict using seed 11\"\n", "git status\n", "git log --oneline --graph --all --decorate -10\n", "git switch main\n", "cat homework/practice/settings.txt\n", "```\n", "\n", "- Back on `main`, the seed should still be `20261008`. The merge commit is on `seed-b`.\n", "- In a real simulation, changing the seed can change the result. Rerun the calculation and record the seed.\n", "- To cancel a conflicted merge, run `git merge --abort` **before resolving and committing**. Because we started clean, this restores the pre-merge state. It doesn't undo a committed merge.\n", "\n", "Reference: [Git merge and conflict handling](https://git-scm.com/docs/git-merge).\n" ] }, { "cell_type": "markdown", "id": "lab04-26", "metadata": {}, "source": [ "## Keep this beside your homework\n", "\n", "### A small command reference\n", "\n", "| Question or action | Command |\n", "| --- | --- |\n", "| Where am I? | `pwd` |\n", "| What changed, and what is staged? | `git status` |\n", "| What changed in tracked files since staging? | `git diff` |\n", "| What will the next commit contain? | `git diff --staged` |\n", "| Stage a particular file | `git add filename` |\n", "| Record the staged changes | `git commit -m \"Explain the change\"` |\n", "| Read the history and branch labels | `git log --oneline --graph --all --decorate` |\n", "| Create and switch to a branch | `git switch -c branch-name` |\n", "| Switch to an existing branch | `git switch main` |\n", "| Merge into the current branch | `git merge branch-name` |\n", "| Check remote URLs | `git remote -v` |\n", "| Download history from my fork | `git fetch origin` |\n", "| Download new course history | `git fetch upstream` |\n", "| Merge course updates into my current branch | `git merge --no-edit upstream/main` |\n", "| Update from my own fork when `main` can fast-forward | `git pull --ff-only origin main` while on `main` |\n", "| Publish `main` | `git push origin main` |\n", "| Publish a new feature branch and track it | `git push -u origin branch-name` |\n", "\n", "1. Run `git status` before and after a change.\n", "2. Read the diff. Stage the files you want, then inspect the staged diff.\n", "3. Commit. Push when you're ready to share the commits.\n", "4. If Git stops with an error, read it before trying another command.\n" ] }, { "cell_type": "markdown", "id": "lab04-27", "metadata": {}, "source": [ "### When something stops you\n", "\n", "| What you see | What to check |\n", "| --- | --- |\n", "| `not a git repository` | Run `pwd`; enter the clone, not its parent directory. |\n", "| `Author identity unknown` | Set `user.name` and `user.email` inside the repository. |\n", "| `nothing to commit` | Save your file, then check `git status`. Did you already commit the change? |\n", "| `Permission denied (publickey)` when cloning, fetching, or pushing your fork | Check your fork's SSH URL, `ssh-add -l`, and that the public key is on your GitHub account. Repeat the connection test above. |\n", "| No connection to the authentication agent | Rerun the `ssh-agent` and `ssh-add` block in this terminal. |\n", "| Push rejected as non-fast-forward | The remote has history your branch doesn't contain. Fetch, look at the graph, and show me before combining the changes. |\n", "| Switching or merging would overwrite local changes | Look at the changes and commit the work you want to keep before switching. Don't discard it just to get past the error. |\n", "| Conflict markers in a file | Resolve the content, remove markers, stage, inspect, and complete the merge. |\n", "\n", "- Save notebooks before staging. Outputs and metadata can make diffs large; clear outputs you don't need.\n", "- Agree on who edits each notebook. Move frequently shared code into small text modules to make changes easier to compare and merge.\n", "- GitHub's notebook preview displays the file; it doesn't run the Python code.\n" ] }, { "cell_type": "markdown", "id": "lab04-28", "metadata": {}, "source": [ "### Final check: ready for the next homework session\n", "\n", "Show your partner:\n", "\n", "- Your fork of `jmduarte/phys142` and `homework/assignment1/README.md`.\n", "- A commit and its diff. Explain the change.\n", "- A PR merged into **your own fork**, with the same change in local `main`.\n", "- `git remote -v`: identify `origin` and `upstream`.\n", "- A clean working tree, with local `HEAD` matching your GitHub `main`.\n", "\n", "Explain:\n", "\n", "- How will you bring in a new course handout without losing your homework?\n", "- Why isn't `git pull origin main` enough when the update is only in the course repository?\n", "- What comes after `git fetch upstream`?\n", "- How do **Git and GitHub** differ? What do **save**, **commit**, and **push** do?\n", "- What does each of **branch**, **fork**, and **clone** create?\n", "- Why is a **pull request** different from **pull**?\n", "\n", "### Optional independent challenge\n", "\n", "1. Create `add-run-notes`. Add a section to `homework/README.md` explaining the seed and sample count in `homework/practice/settings.txt`.\n", "2. Stage the change, read the diff, and commit.\n", "3. Push with `git push -u origin add-run-notes`.\n", "4. Open a PR to **your fork's** `main`. Read the diff and merge.\n", "5. Switch your local checkout to `main`, then run `git pull --ff-only origin main`.\n" ] }, { "cell_type": "markdown", "id": "lab04-29", "metadata": {}, "source": [ "### References and more practice\n", "\n", "- [Pro Git: version control](https://git-scm.com/book/en/v2/Getting-Started-About-Version-Control)\n", " and [recording changes](https://git-scm.com/book/en/v2/Git-Basics-Recording-Changes-to-the-Repository).\n", "- [GitHub: Hello World](https://docs.github.com/en/get-started/using-github/hello-world),\n", " [forks](https://docs.github.com/en/pull-requests/how-tos/work-with-forks/fork-a-repo),\n", " and [SSH authentication](https://docs.github.com/en/authentication/connecting-to-github-with-ssh).\n", "- [Learn Git Branching](https://learngitbranching.js.org/?NODEMO): an optional\n", " interactive sandbox for more branching practice.\n", "\n", "Diagrams use [Mermaid](https://mermaid.js.org/). `A` and `B` are teaching labels for commits, not actual hashes to use in Git commands.\n" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3" }, "title": "Lab 04: Git and GitHub" }, "nbformat": 4, "nbformat_minor": 5 }