Lab 04 — Git & GitHub Workflow¶
Session: Week 2 · Session 4 · 90 min CLO: CLO-1 (reproducibility foundation), CLO-3 Difficulty: Beginner
Learning objectives¶
By the end of this lab you can:
- Explain the working tree → staging area → commit pipeline.
- Create, switch, merge, and delete branches.
- Push to GitHub and pull changes without losing work.
- Write commit messages that explain why, not just what.
- Recover from a simple "oops" (amend, restore a file).
Problem statement¶
Your course repo is about to carry every lab, assignment, and project file
for 16 weeks. You must prove you can operate Git safely: commit cleanly,
work on a branch without breaking main, and merge without drama. You will
simulate a realistic solo workflow: a feature branch, a commit, a fix, and
a merge back to main.
Dataset requirements¶
None — you work with small text/Python files you create.
Step-by-step tasks¶
Work in your data-science-course repository from Lab 01 (create it if
needed).
- Baseline: confirm
git statusis clean andgit log --onelineshows your previous commits. - Create a branch
feature/eda-notesand switch to it. - Add a file
eda-notes.mdwith two bullet points about the tips dataset. Stage and commit with a why-style message. - Switch back to
main. Add a second bullet toeda-notes.md— deliberately creating a different version. Commit it onmain. - Merge the feature branch into
main. Resolve the conflict in favor of keeping both bullet sets (edit the file, thengit add+ commit). Record the merge commit. - Push
mainto GitHub. Verify the file on github.com. - Simulate a teammate: clone the repo into a second folder, add a file,
commit, and push. Then
git pullin your original folder — you must see the new file. - Cleanup: delete the merged
feature/eda-notesbranch locally.
Starter code¶
git status
git log --oneline
git switch -c feature/eda-notes
# ... edit eda-notes.md, add two bullets ...
git add eda-notes.md
git commit -m "Add EDA notes for tips dataset"
git switch main
# ... edit eda-notes.md with a different bullet, commit ...
git merge feature/eda-notes
# if conflict: edit file, git add eda-notes.md, git commit
git push origin main
git branch -d feature/eda-notes
Expected output¶
git log --onelineshows at least: an initial commit, the feature commit, a main commit, and a merge commit.git statusclean at the end.git branchlists onlymain(and* main).- The pushed file appears on github.com.
- The second clone's file appears after
git pull.
Questions¶
- In your own words: what is the difference between
git addandgit commit? - Why did the merge conflict happen? (Both versions changed the same lines.)
- What does
git push origin maindo, exactly? - Why commit small, focused changes with message describing the why?
- What is one risk of
git commit -amthatgit add+git commitavoids?
Challenge task¶
Practice recovery: make a small change to a tracked file, then restore it
with git restore <file>. Next, commit a message you regret and fix it
with git commit --amend. Finally, add a Labs/ directory with this
lab's file, commit it, and push — your repo is now set up for the rest of
the course. Document all three commands you used in eda-notes.md.
Marking rubric¶
| Criteria | Max | Notes |
|---|---|---|
| Branch created, used, merged, deleted | 4 | log shows feature + merge commits |
| Conflict resolved keeping both versions | 3 | both bullet sets present |
| Pushed to GitHub, verified remotely | 3 | repo visible |
| Clone → push → pull round trip | 3 | second folder worked |
| Why-style commit messages | 2 | reviewed in log |
| Answers to questions | 2 | Q2, Q5 correct |
| Challenge: restore + amend + Labs/ pushed | 3 | all three commands |
| Total | 20 |