DS1 · Gap lecture G2
One isolated environment per project, and a history you can always recover. Every workshop and the capstone ship as GitHub repos.
This afternoon
| # | Section | Minutes |
|---|---|---|
| 1 | Isolated environments | 25 |
| 2 | Git’s data model | 35 |
| – | Break | 10 |
| 3 | Branches and merges | 40 |
| 4 | GitHub workflow | 20 |
| 5 | Lab: portfolio repo, check_repo.py | 50 |
Recall · this morning, 10 minutes
R.1 · Broadcasting
Shape of (5, 1) + (1, 3)?
R.2 · pandas
Rows in df.loc[0:2] and df.iloc[0:2]?
R.3 · Least squares
Why lstsq, not inv?
Why it matters
Phase 1
NumPy, scikit-learn
Phase 2
TensorFlow, Keras
Phase 4
PyTorch, LangChain
Phase 6
FastAPI, Docker
One environment per project; every project in Git.
1 · Environments
python -m venv .venv
source .venv/bin/activate
# Windows: .venv\Scripts\activate
which python
# .../ds1-portfolio/.venv/bin/python
pip install -r requirements.txt
ds1-portfolio/
├─ .venv/ # never committed
├─ .gitignore
├─ requirements.txt
├─ README.md
└─ labs/
Activating puts .venv/bin first on PATH, so python and pip resolve there.
1 · Definition
| Specifier | Means | Use in |
|---|---|---|
| numpy>=1.26 | 1.26 or newer | requirements.txt |
| numpy~=1.26.0 | 1.26.x patches | a library you trust |
| numpy==1.26.4 | exactly this | a lock file |
Commit requirements.txt. Never commit .venv/.
2 · Git’s data model
Learn the model, not just the commands, and you can recover from almost any mistake.
2 · Worked example
\(\text{id} = \operatorname{SHA1}\big(\texttt{"blob "} \Vert \text{len} \Vert \texttt{\textbackslash 0} \Vert \text{content}\big)\)
content = b"hello\n" # 6 bytes
header = b"blob %d\0" % len(content) # b"blob 6\x00"
hashlib.sha1(header + content).hexdigest()
# 'ce013625030ba8dba906f756967f9e9ca394464a'
printf 'hello\n' | git hash-object --stdin
# ce013625030ba8dba906f756967f9e9ca394464a
Same content, same id, on any laptop.
Concept question 1
A
Different: the times differ
B
Identical
C
Identical only if the names match
D
Random each time
Vote alone, discuss with a neighbour, vote again.
2 · Data model
git add
git commit
git restore brings a stored version back
2 · Definitions
Add env files
Add README
Name the group
Merge
Describe the repo
feature/readme
main, HEAD
merge base of D and C
3 · Definition
| Changed since base O | Result |
|---|---|
| Only side A | take A |
| Only side B | take B |
| Both, the same way | take it |
| Both, differently | conflict: you decide |
If O is your own commit, the branch just moves forward.
Concept question 2
A
Report a conflict
B
Combine both changes
C
Keep only side A
D
Fast-forward
Vote alone, discuss with a neighbour, vote again.
3 · Worked example
<<<<<<< HEAD
Work for group AI-2.
=======
Labs from the DS1 path.
>>>>>>> feature/readme
1 · Why it stopped
Merge base B; both sides changed line 3 differently
2 · Resolve
Write the intended line, delete the markers
3 · Finish
git add README.md, then git commit
4 · GitHub
git remote add origin https://github.com/<user>/ds1-portfolio.git
git push -u origin main
Commits
One change each, imperative message
Branches
Branch, pull request, merge
Never push
.venv/, data dumps, API keys
Practice · from worked example to blank page
git commit
git push --force
(edit README.md, delete the markers)
git status
git add README.md
P.1 · Parsons
Order the steps. One line is a distractor.
P.2 and P.3
Fill the .gitignore; pick the right git diff. Sheet: exercises.md.
5 · Lab
| Tier | Task |
|---|---|
| Core | Steps 1–8: repo, venv, conflict, merge, push |
| Stretch | Pull request for labs/01; amend before push |
| Challenge | CI with pytest; restore a deleted file |
python check_repo.py ~/ds1-portfolio # 9 checks, all PASS
AI rule: type every core command yourself.
Exit ticket · 3 minutes
E.1
Which command shows staged but uncommitted changes?
E.2
Why is .venv/ in .gitignore?
Also show check_repo.py output: 9 of 9 PASS.
Recap
Environment
One .venv per project
History
Ids are content hashes
Merging
Conflicts only on shared lines
GitHub
No venvs, no secrets
Next
Day 2, Sat 5 Dec: math for ML and scikit-learn baselines. Push labs/01 first.