Foundations: Python, Git and toolsLoading progress…

Forks and branches

Use a remote, pull request and automated check to propose a reviewable change.

Two different things that sound alike

A branch is a movable name inside one repository. A fork is a second hosted repository, a full copy under your account, with its own branches. You fork when you are allowed to read a project but not to push to it. You branch to isolate one change, in any repository.

Step 1 of 5

Start

Only the upstream exists. You can read it, but you cannot push to it.

acme/shop (upstream)

main 3943813

learner/shop (fork)

(does not exist yet)

your laptop

(no clone yet)
Step through the fork workflow. The three boxes are real repositories in the simulation.

Predict first. You click Fork on a project you do not own. Which repository changed?

origin, upstream, and staying current

After git clone of your fork, origin is the fork. By convention you add a second remote named upstream that points at the original, so you can fetch what the maintainers do. You have read access to it but not write access, so pushes go to origin only.

acme/shop (upstream, you cannot push)

main 3943813

learner/shop (your fork, origin)

main 3943813

your laptop

main 3943813 origin/main 3943813

Your fork is up to date with the upstream..

Press a button. Every command runs on real simulated repositories.
Let the maintainers commit, then catch your fork up two ways: the website button, or fetch upstream, merge, push origin. Try pushing to upstream too.
git clone https://forge.example/learner/shop.git
git remote add upstream https://forge.example/acme/shop.git
git switch -c fix-typo      # one branch per change
git push -u origin fix-typo # to YOUR fork
# later, to catch up:
git switch main && git fetch upstream && git merge upstream/main && git push origin main
Chapter context

GitHub hosts repositories and adds collaboration around Git objects. A pull request is a review and discussion mechanism; the commits and branch history still follow Git rules.

Chapter reference: math, worked example & code

This section belongs to the whole chapter, so it is the same on every lesson in it and may cover a different lesson's topic. The code for the experiment you just ran is inside the experiment itself.

Math and notation

For independent jobs with durations t1 and t2 running simultaneously, ideal elapsed time is max(t1,t2), excluding startup and queueing. A dependency adds a sequential edge and can make durations add instead.

Worked example

A build takes 3 minutes. Two test jobs taking 4 and 6 minutes start after the build and run together. The ideal critical path is 3 + max(4, 6) = 9 minutes, not 13. Real runners can add scheduling overhead.

Reference code

The following example uses the Python standard library and does not call a remote service.

build, tests = 3, [4, 6]
assert build + max(tests) == 9
assert build + sum(tests) == 13

Python examples are provided for study and local execution; this page does not execute Python.

Common mistakes

A green check is evidence for the checks that ran, not proof of every behavior. Forked code must not automatically receive trusted secrets.