Foundations: Python, Git and toolsLoading progress…

Remotes and synchronization

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

A remote is another copy of the repository

Git has no central server built in. Every clone is a full repository. A remote is just a name for the address of another copy, most often one on a hosting service. When you run git clone you get every commit, and Git writes down one remote called origin.

git clone https://forge.example/acme/shop.git
cd shop
git remote -v
# origin  https://forge.example/acme/shop.git (fetch)
# origin  https://forge.example/acme/shop.git (push)
git branch -vv
# * main 3943813 [origin/main] Add cart

Notice origin/main in the brackets. That is a remote-tracking branch: your repository's bookmark for "where main was on origin the last time I talked to it". You cannot commit on it. Only fetch, pull and push move it.

Fetch, pull and push move different things

git fetch downloads new commits and moves your bookmarks. It never touches your branches or your files. git pull is fetch followed by an integration (a merge, or a rebase if you ask for one). git push uploads your commits and moves the branch on the server, but only if that move is a fast-forward.

The server (origin)

b02e285 Initial commitb02e285Initial co…3943813 Add cart3943813Add cartHEAD → main

Your laptop (origin/main is your last known copy of the server)

b02e285 Initial commitb02e285Initial co…3943813 Add cart3943813Add cartHEAD → mainorigin/main

What git status says right now

On branch main Your branch is up to date with 'origin/main'.
Press a button. Every command runs on real simulated repositories.
Make Maya push, make a commit of your own, then try fetch, pull and push in different orders. Compare git status with the two graphs.

Predict first. Maya pushed two commits to the server a minute ago. You have not run any Git command since. You type git status. What does it say about origin/main?

When both sides have moved

If the server has commits you do not have and you have commits it does not have, the histories have diverged. A push would make the server drop Maya's work, so the server refuses it ("fetch first" when you have not even downloaded her commits, "non-fast-forward" when you have). The fix is always to integrate first: git pull (current Git asks you to choose merge or rebase when branches have diverged) and then push.

git fetch                     # see what is new, change nothing
git log main..origin/main     # read the incoming commits
git pull --no-rebase          # merge them (or: git pull --rebase)
git push

Predict first. A push is rejected with (fetch first). What is the best first move?

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.