DS1 · Gap lecture G2

Dev Environment and Git

One isolated environment per project, and a history you can always recover. Every workshop and the capstone ship as GitHub repos.

Day 1 · Fri 4 Dec 2026

1:00–4:00 · Lab 16

Group AI-2

This afternoon

From a clean laptop to a pushed repo

#SectionMinutes
1Isolated environments25
2Git’s data model35
–Break10
3Branches and merges40
4GitHub workflow20
5Lab: portfolio repo, check_repo.py50

Recall · this morning, 10 minutes

Three questions on Lecture 01

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

Four phases, four conflicting toolsets

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

A private Python for each project

Terminal

python -m venv .venv

source .venv/bin/activate

# Windows: .venv\Scripts\activate

which python

# .../ds1-portfolio/.venv/bin/python

pip install -r requirements.txt

Text

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

requirements.txt rebuilds the environment anywhere

SpecifierMeansUse in
numpy>=1.261.26 or newerrequirements.txt
numpy~=1.26.01.26.x patchesa library you trust
numpy==1.26.4exactly thisa lock file

Commit requirements.txt. Never commit .venv/.

2 · Git’s data model

Every version has a fingerprint computed from its content

Learn the model, not just the commands, and you can recover from almost any mistake.

2 · Worked example

Compute a Git object id by hand

\(\text{id} = \operatorname{SHA1}\big(\texttt{"blob "} \Vert \text{len} \Vert \texttt{\textbackslash 0} \Vert \text{content}\big)\)

Python

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

Two learners make identical files on different laptops. The blob ids are:

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

A change reaches history in two steps

Working treefiles you edit
Staging areanext snapshot
Repositorycommits

git add

git commit

git restore brings a stored version back

2 · Definitions

Commits point to parents; a branch is a movable name

A

Add env files

B

Add README

D

Name the group

M

Merge

C

Describe the repo

feature/readme

main, HEAD

merge base of D and C

3 · Definition

Git merges region by region against the base

Changed since base OResult
Only side Atake A
Only side Btake B
Both, the same waytake it
Both, differentlyconflict: you decide

If O is your own commit, the branch just moves forward.

Concept question 2

Since the merge base, side A edited line 2 and side B edited line 10. git merge will:

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

A conflict, and how to resolve it

Text

<<<<<<< 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

Push once, then keep the remote clean

Terminal

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

Finish a conflicted merge

Terminal

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

Core first, then stretch, then challenge

TierTask
CoreSteps 1–8: repo, venv, conflict, merge, push
StretchPull request for labs/01; amend before push
ChallengeCI with pytest; restore a deleted file
Terminal

python check_repo.py ~/ds1-portfolio # 9 checks, all PASS

AI rule: type every core command yourself.

Exit ticket · 3 minutes

Two questions before you leave

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

Habits for every workshop from now on

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.

Home