1.4.11Python & Scientific Computing

Git version control basics

3,646 words17 min readdifficulty · medium3 backlinks

Core Concepts


The Three States of Files

Figure — Git version control basics

Essential Commands - Derived from Workflow

1. Initializing and Cloning

2. Basic Workflow Commands

3. Branching and Merging

4. Remote Operations


Worked Examples


Common Mistakes


Git Workflow Patterns


Best Practices for ML Projects



Recall Feynman Explanation (Explain to a 12-year-old)

Imagine you're writing a story in a magic notebook. Every time you finish a chapter, you can press a button called "Save Checkpoint" (that's a commit). The magic notebook remembers every checkpoint you ever made.

If you write something and don't like it later, you can flip back to any old checkpoint and start over from there. You never lose your old work!

Now, let's say you want to try a different ending for your story. You create a branch—it's like a parallel universe for your story. In this branch, the hero wins differently. In the main story, things stay the same. Later, if you like the new ending, you can merge it back into the main story.

Your friend also has a copy of the magic notebook (on their computer). When you both make changes, you push your checkpoints to a shared cloud notebook (GitHub), and you pull their checkpoints to see what they wrote. If you both changed the same sentence, you have a conflict—you have to decide whose version to keep. That's Git! It's a time machine + parallel universes + cloud sharing for your code.


Connections


#flashcards/ai-ml

What is a Git repository? :: A directory tracked by Git containing project files and a .git folder with complete version history, commits, and branch metadata.

What are the three states of files in Git?
Modified (working directory), Staged (index/staging area), and Committed (stored in .git repository).
What does git add do?
Stages changes from the working directory to the staging area, marking them for inclusion in the next commit.
What is a commit in Git?
A snapshot of the project at a specific time, identified by a SHA-1 hash, containing author info, timestamp, message, and pointer to parent commit(s).
What is a branch in Git?
A movable pointer to a commit, representing an independent line of development. Just41 bytes referencing a commit hash.

What is the difference between git fetch and git pull? :: git fetch downloads remote changes without merging; git pull does fetch + merge automatically.

Why use a .gitignore file?
To prevent Git from tracking auto-generated files, large datasets, secrets, and environment-specific files that shouldn't be in version control.
What does git checkout -b feature-x do?
Creates a new branch named "feature-x" and switches to it in one command (shorthand for git branch + git checkout).
What is a merge commit?
A commit with two (or more) parent commits, created when merging branches that have diverged—combines changes from both branches.
What does HEAD point to in Git?
The current branch reference or commit you're working on. Determines where new commits will be added.
Why use feature branches?
To isolate experimental work from the stable main branch, enabling parallel development without breaking production code.
What is the purpose of commit messages?
To document what changed and why, making history searchable and helping future developers understand the evolution of the codebase.
How does Git store commits efficiently?
By storing only the differences (deltas) between commits, not full file copies, using content-addressable storage.
What is a fast-forward merge?
When the target branch hasn't diverged, Git simply moves the branch pointer forward instead of creating a merge commit.
What does git push origin main do?
Sends local commits from the main branch to the remote repository named "origin" and updates the remote branch pointer.
Why are tags useful in ML projects?
They mark specific commits as significant (e.g., production models), enabling exact reproduction of a model version by checking out the tag.

Concept Map

creates

stores history in

contains

git add

git commit

snapshot is

points to

links to

git clone / push

syncs with

Git DVCS

Repository

Commit snapshot

Branch pointer

Working Directory

Staging Area

Repository .git

Remote GitHub

Hinglish (regional understanding)

Intuition Hinglish mein samjho

Git ek version control system hai jo tumhare code ka time travel possible banata hai. Socho agar tumnek Python model likha, phir tuning karte-karte kuch broke ho gaya — Git ke saath tum instantly purane working version pe wapas jaa sakte ho. Ye especially ML projects ke liye zaroori hai kyunki experiments bahut hote hain aur track karna mushkil.

Teen stages hain: Modified (tumne file change kari but abhi Git ko bataya nahi), Staged (tumne git add kiya,

Go deeper — visual, from zero

Test yourself — Python & Scientific Computing

Connections