Level 0: Foundation
★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.Save points you can share
Writing code is like writing a long report with a team. You want save points you can go back to, a way to try an idea without wrecking the working version, and a way to combine everyone’s changes. Git gives you all three: each commit is a save point of the whole project, a branch lets you experiment on a copy of the timeline, and a merge brings the timelines back together. GitHub hosts the project so a team can review each other’s changes in pull requests before they’re merged.
git init; git commit -m "initial"
Every result in a paper or a design review should trace back to an exact version of the code. Git provides that traceability (tag the commit that produced the figures), and pull requests with review and automated tests catch bugs before they reach a mission-critical analysis or a robot.
- 1. A commit is…
- 2. A branch lets you…
- 3. A pull request is…
Level 1: Beginner
★★☆☆☆ Basic⏱ 25 minSecondary-school mathematics: arithmetic and elementary algebra.Everyday commands
git clone URL; cd repo
git switch -c fix-eps-telemetry # new branch
# edit files …
git status; git diff # what changed?
git add src/eps.py tests/test_eps.py # stage
git commit -m "fix(eps): clamp SoC estimate to [0, 1]"
git push -u origin fix-eps-telemetry # then open a pull request on GitHub
git switch main; git pull # update after the merge
git log --oneline --graph --all # see the history.gitignore keeps generated files, data and secrets out of the repository. Never commit credentials; use environment variables or a secrets manager.
The three areas
Working tree (your files) → git add → staging area (the next commit’s contents) → git commit → repository (history). git restore undoes working-tree changes; git restore --staged unstages.
- 1. git add moves changes into…
- 2. Which command creates and switches to a branch?
- 3. Where should data files and secrets go?
Level 2: Intermediate
★★★☆☆ Intermediate⏱ 35 minUndergraduate students and practising engineers.How Git stores history
Every object is named by the SHA-1 hash of its content (SHA-256 in newer repositories):
- blob: file contents, hashed as
"blob <size>\0" + content. - tree: a directory listing (names → blob/tree ids).
- commit: a tree id, parent commit id(s), author, message.
Change one byte and every id above it changes, so history is tamper-evident. A branch is a file containing one commit id; HEAD says which branch you’re on.
Merge vs rebase
- Merge: if main is an ancestor of feature, main fast-forwards (just moves). Otherwise Git makes a merge commit with two parents, combining changes since the merge base (best common ancestor) by a three-way merge.
- Rebase: replays your commits on top of the new main as new commits, giving a linear history. Never rebase commits others have already pulled.
Pull-request practice
Small, focused PRs (one idea, a few hundred lines at most), a clear description (what, why, how tested), CI green before review, reviewers check logic and tests, squash or merge per team convention. Short-lived branches merged often (trunk-based development) avoid painful conflicts.
- 1. A fast-forward merge happens when…
- 2. Rebasing published commits is risky because…
- 3. A three-way merge compares ours and theirs with…
Level 3: Advanced
★★★★☆ Advanced⏱ 30 minGraduate level, with full derivations and proofs.Three-way merge logic
For each region, with base B, ours O and theirs T:
- O = T: take it.
- O = B: only they changed it, take T.
- T = B: only we changed it, take O.
- Otherwise it is a conflict, marked
<<<<<<<,=======,>>>>>>>for a human to resolve.
Real Git aligns regions with a diff algorithm (Myers, histogram) and handles insertions and deletions, but the decision rule is the same.
Why long-lived branches hurt
If a file has N regions and each branch independently changes k of them, the probability that at least one region was changed by both is
a birthday-problem effect: it grows with the square of the work done on each side. Merging small changes often keeps k small.
Bisecting
git bisect binary-searches the history for the commit that introduced a bug: test runs for n commits (see C2.6).
- 1. Ours changed a line, theirs left it as in base. Result:
- 2. Conflict probability grows roughly like…
- 3. Bisecting 1000 commits needs about…
Level 4: Expert
★★★★★ Expert⏱ 30 minResearchers: original papers and open problems.Merging, measured
Exercise 1. Your blob_hash reproduces Git exactly: “hello world\n” → 3b18e512… and the empty file → e69de29b…. On the sample graph, merge-base(G, H) = E, C can fast-forward to G, and the topological log is G F E D C B A.
Exercise 2: conflict risk vs branch lifetime (a 500-line file, each branch edits 3 random lines per day, 400 simulated merges per point):
| branch lifetime | simulated P(conflict) | exact |
|---|---|---|
| 1 day | 0.01 | 0.018 |
| 3 days | 0.16 | 0.152 |
| 1 week | 0.60 | 0.601 |
| 2 weeks | 0.97 | 0.979 |
| 30 days | 1.00 | 1.000 |
A one-week branch is more likely than not to conflict. Real edits cluster in “hot” regions, which makes this worse.
Git in AI, robotics and aerospace
- Traceability: tag the commit that produced each figure, model or flight-software build.
- Pull requests with CI: tests, linters and formatting checks before merge (C2.2, C2.3).
- Large files: Git LFS or DVC for datasets and model weights; keep them out of normal history.
- Monorepos and ROS workspaces: submodules and workspace tools manage many packages.
References
- S. Chacon, B. Straub (2014). Pro Git, 2nd ed. Apress (free at git-scm.com/book).
- E. W. Myers (1986). “An O(ND) difference algorithm and its variations.” Algorithmica, 1.
- G. Wilson et al. (2017). “Good enough practices in scientific computing.” PLOS Computational Biology, 13(6).
- Conventional Commits specification (conventionalcommits.org).
- GitHub Docs: About pull requests, About protected branches.