Chapter 18 — Exercises
Overview
This chapter contains structured exercises that cover the entire Student Guide workflow. Complete them in order — each exercise builds on the previous.
You will use the group's example repository for these exercises. The example repository is a small, intentionally simple physics code designed for practice without the risk of affecting real research code.
Before starting
Confirm with the maintainer that you have been added as a collaborator on the example repository, and obtain its GitHub URL.
Part 1: Setup (Chapters 4–6)
Exercise 1.1 — Verify Your Environment
Confirm your development environment is correctly configured:
git --version
git config --global user.name
git config --global user.email
git config --global core.editor
git config --global init.defaultBranch
ssh -T git@github.com
Expected output for SSH: Hi your-username! You've successfully authenticated...
Record any configuration that is wrong and fix it before proceeding.
Exercise 1.2 — Clone the Example Repository
Clone the group's example repository:
git clone git@github.com:ORG/example-repository.git
cd example-repository
git remote -v
git log --oneline -5
Verify:
- The remote URL starts with
git@github.com: - The log shows at least one commit
Exercise 1.3 — Explore the Structure
Answer these questions in your notes:
- What files are at the top level?
- Is there a
src/directory? Atests/directory? - What is this code supposed to do (from the README)?
Part 2: Branches and Commits (Chapters 7–9)
Exercise 2.1 — Your First Branch
Create a feature branch for your first contribution.
The task: add your name and a one-line description to the CONTRIBUTORS.md file.
Edit CONTRIBUTORS.md and add one line:
Stage and commit:
git status
git diff
git add CONTRIBUTORS.md
git diff --staged
git commit -m "Add [Your Name] to contributors list"
Exercise 2.2 — Atomic Commits
The task: add a new Python function to the example code.
- Create a branch:
feature/add-your-function - Write a simple mathematical function (e.g., a Gaussian or step function) in
src/ - Commit the function:
"Add [function name] function to src/" - Write a test for the function in
tests/ - Commit the test separately:
"Add unit test for [function name]"
Result: two separate, atomic commits. Verify with:
Exercise 2.3 — Interactive Staging
In the file you created for Exercise 2.2, make two unrelated changes:
- Fix a typo in a comment
- Add a second function
Use git add -p to stage only the typo fix and commit it.
Then stage the second function and commit it separately.
Verify you have three commits (original function, typo fix, second function).
Part 3: Push and Pull Request (Chapters 10–11)
Exercise 3.1 — Push Your Branch
Push your docs/add-your-name branch to GitHub:
Verify the branch appears in the GitHub repository.
Exercise 3.2 — Open a Pull Request
Open a Pull Request for your docs/add-your-name branch:
- Go to the repository on GitHub.
- Click "Compare & pull request".
- Fill in the PR template:
- Title:
Add [Your Name] to contributors list(imperative) - Motivation: Why are you adding yourself?
- Summary of changes: What file was modified?
- Testing: What verification did you perform?
- Related issue:
Noneor an actual issue if one exists - Assign the maintainer as reviewer.
- Apply the label
type: docs. - Create the PR.
Exercise 3.3 — Draft PR
Push your feature/add-your-function branch and open a Draft PR:
On GitHub, open a draft PR with:
- Title:
Add [function name] function - Mark it as a draft (click the arrow next to "Create pull request")
This exercises the concept of using draft PRs for work in progress.
Part 4: Review (Chapter 12)
Exercise 4.1 — Receive a Review
Ask a colleague (or the maintainer) to review your docs/add-your-name PR
and leave at least one comment.
Respond to the comment:
- Make the requested change (if any).
- Commit and push.
- Reply to the comment explaining what you did.
- Mark the conversation as resolved.
- Request re-review.
Exercise 4.2 — Give a Review
Find a colleague who has an open PR. Review it:
- Click "Files changed".
- Leave at least:
- One inline comment (click
+next to a line) - One overall comment using "Review changes"
- Mark it as either "Approve", "Comment", or "Request changes".
Part 5: Updating Branches (Chapter 14)
Exercise 5.1 — Simulate a Diverged Branch
- Ask the maintainer to push one commit to
mainafter you created your feature branch. -
Run:
Confirm you are behind. -
Rebase:
-
Force-push:
-
Verify the PR shows "no conflicts" on GitHub.
Part 6: Conflict Resolution (Chapter 13)
Exercise 6.1 — Simulate a Merge Conflict
Work with a colleague:
- Both of you branch from the same commit on
main. - Both edit the same line in the same file (e.g.,
CONTRIBUTORS.mdline 1). - Both commit and push your branches.
- One person's PR is merged first.
-
The other person:
-
Resolve the conflict, stage the file, continue the rebase, and push.
Part 7: Recovery (Chapter 15)
Exercise 7.1 — Commit to main Recovery
- Check out
main. - Make a trivial commit directly to
main(e.g., add a space toREADME.md). - Do not push.
-
Practice the recovery:
-
Verify your commit is now only on
feature/recovered.
Exercise 7.2 — Stash Workflow
- Start editing a file on
feature/add-your-function. -
Stash your changes:
-
Switch to
main, pull, switch back. -
Pop the stash:
-
Verify your changes are restored.
Part 8: Full Cycle Completion
Exercise 8.1 — Merge Your PR
After your docs/add-your-name PR is approved:
- The maintainer will squash-merge it.
-
After the merge, clean up locally:
-
Verify your name is now in
CONTRIBUTORS.mdonmain.
Completion Checklist
- Exercise 1.1 — Environment verified
- Exercise 1.2 — Repository cloned
- Exercise 1.3 — Structure explored
- Exercise 2.1 — First branch and commit created
- Exercise 2.2 — Atomic commits demonstrated
- Exercise 2.3 — Interactive staging used
- Exercise 3.1 — Branch pushed to GitHub
- Exercise 3.2 — Pull Request opened with complete template
- Exercise 3.3 — Draft PR created
- Exercise 4.1 — Responded to review comments
- Exercise 4.2 — Reviewed a colleague's PR
- Exercise 5.1 — Branch rebased onto updated
main - Exercise 6.1 — Merge conflict resolved
- Exercise 7.1 — Commit-to-main recovery practiced
- Exercise 7.2 — Stash workflow practiced
- Exercise 8.1 — PR merged and branch cleaned up
When all boxes are checked, you have completed the Student Guide.
Proceed to regular development work on group projects. If you encounter a situation not covered here, consult the FAQ (Chapter 16), the Cheat Sheet (Chapter 17), or ask the maintainer.