1.4.11 · D1Python & Scientific Computing

Foundations — Git version control basics

3,479 words16 min readBack to topic

Before you touch a single command in the parent note, you need to know what every word and symbol on that page actually means. This page assumes you have never seen Git. We build each idea from a picture, then say why the topic needs it. We introduce the commands (git init, git add, git commit, …) only after the idea each one acts on is on the table — never before.


The most basic picture: a folder that remembers

To even tell Git which folder to watch, you type instructions at a text prompt — the command line. For now just know that a Git instruction is a short line of text you type there; we will explain each specific instruction the moment its underlying idea has been defined, and never sooner.

Figure — Git version control basics

Look at the figure. The big box is your working directory — the files you can see and edit right now. The small shaded box inside it labelled .git is Git's private album of photographs. You never edit .git by hand; Git fills it as you work.


The photograph itself: a commit

Now the central word of the whole topic.

Each commit carries a small label so you can find it again:


Lining photos up: the parent arrow

Figure — Git version control basics

In the figure, each amber circle is a commit and each arrow points from a commit back to its parent. Read the arrows right-to-left to travel back in time.


The three rooms a file lives in

The parent's most important diagram is "the three states". Here is what each really means, as three rooms a file passes through on its way into a photograph.

Figure — Git version control basics

The two arrows between the rooms are the two most-used commands. Read the figure as a doorway diagram: a change walks from the desk (Modified) onto the photo table (Staged) through the door called git add, then into the drawer (Committed) through the door called git commit.


Movable labels: branch, tag and HEAD

Moving that arrow needs a command — and now that we know what the arrow is, we can name it:

Figure — Git version control basics

The figure shows two branch labels (main and feature) clipped to different commits, with the amber HEAD arrow resting on feature — telling you the next photo joins the feature chain.


How merging joins two chains


Talking to another computer: remotes


Prerequisite map — how these pieces feed the topic

Read the map below bottom-up toward TOPIC: every box is one foundation from this page, and the arrows show what must be understood before the box it points to. Start at the top-left roots (a folder, the command line) and trace downward — you can see the whole topic literally grows out of "a folder that remembers". Each strand (staging, branching, syncing) arrives at the same destination, the parent note, showing why all four skills are needed together rather than in isolation.

Command line typing

git init makes a repo

A project folder

Hidden .git album

Commit = one photo

Hash fingerprint IDs it

Parent link builds timeline

Branch = movable label

Tag = fixed label

HEAD = you are here

git checkout moves HEAD

Detached HEAD edge case

Three rooms Modified Staged Committed

Merge joins two chains

Merge conflict needs a human

Remote = twin album

git clone copies the album

push fetch pull

Git version control basics

Once these foundations click, the same photographs power notebook versioning, experiment tracking, model versioning, and CI/CD pipelines — but all of that starts with "a folder that remembers".


Equipment checklist

Test yourself — say the answer out loud before revealing.

What is a repository, in one sentence?
Your project folder plus its hidden .git history drawer — a folder Git is watching; a plain directory has no history drawer.
What is a commit?
One saved snapshot (photograph) of every tracked file at one moment; it never changes once taken.
Why does Git identify commits by a hash instead of numbering them 1, 2, 3?
A content-based fingerprint is guaranteed unique even when many people commit at once on different machines; numbers would collide.
What links commits into a timeline?
Each commit stores its parent — the commit before it — forming a chain you follow backwards.
Name the three rooms a file passes through and the command between each.
Modified → (git add) → Staged → (git commit) → Committed.
Why does the staging area exist at all?
So you can choose which changes go into the next photo, grouping related edits into one clean atomic commit.
What is a branch, physically?
A tiny label (~41 bytes) holding one commit's hash; it slides forward automatically as you add commits.
How does a tag differ from a branch?
A tag is a fixed label pinned to one commit forever; it does not slide forward — used to mark releases/model versions.
What does HEAD point to, normally, and what command moves it?
The branch you are currently on; git checkout moves the HEAD arrow to another branch or commit.
What is a detached HEAD, and why is it risky?
HEAD points directly at a commit with no branch in between; new commits there have no label following them, so they can be lost if you move away.
How do you first obtain a repository that already exists on a remote?
git clone <url> — it copies the entire album to a new local folder and sets up the origin nickname.
What is a remote, and what is origin?
A remote is a full copy of the repo on a server; origin is the conventional nickname for your main one.
What is git pull made of?
git fetch followed by git merge.
When is a merge a fast-forward vs a three-way merge?
Fast-forward when main did not move (just slide the label); three-way when both branches grew, needing a new commit with two parents.
What is a merge conflict and what must you do?
Both branches edited the same line differently, so Git can't choose; you edit the file by hand to keep the right version, then git add and git commit to finish.