Day 2 of 290 - Git & GitHub - The Safety Net Every ML Engineer Needs
Part of my 290-day AI Engineering journey - learning in public, one hour a day, writing everything in plain English so beginners can follow along. The blog is written with the help of AI
What Is This?
You’ve written some code. You make a change - it breaks. You want to go back, but you only have the one file you’ve been editing.
Git solves this. It’s a tool that remembers every single version of your project - who changed it, when, and why - and lets you jump back to any point instantly. Every professional software and ML engineer uses it daily.
The Analogy
Imagine writing an essay in Google Docs. Every few minutes, Google Docs auto-saves and remembers the full history. You can click “Version history” and restore Tuesday’s version anytime.
Git is that - but for your entire project folder, much more powerful, and you control exactly when to save (called a “commit”) and why.
The Concept Explained Simply
Repository (Repo)
A folder that Git is tracking. Every file change inside it is recorded.
Commit
A snapshot you take manually with a description. Like hitting “save” with a message: “at this moment, I fixed the bug where the loss went NaN.”
Branch
A parallel copy of your project. Create a branch to try something experimental. If it works, merge it back. If it fails, delete it. The original (main) was never touched.
GitHub
A website that stores a copy of your repo in the cloud. It’s your backup, your portfolio, and your collaboration platform - all in one.
How Real Companies Use This
At NeuralCorp, nothing gets to production without going through Git. The workflow is:
- Engineer creates a branch, makes changes
- Pushes the branch to GitHub
- Opens a “Pull Request” - a formal request to merge into
main - Senior engineer reviews the code, leaves comments
- Only after approval does it merge to
main
This process catches bugs before they affect customers. It also means you can always look at the history and ask: “which exact change caused accuracy to drop from 94% to 78%?”
Step-by-Step: Try It Yourself
1. Install and configure Git
brew install git
# Tell Git who you are - this goes in every commit
git config --global user.name "Your NAME"
git config --global user.email "Your MailID"
git config --global init.defaultBranch main
2. Create your .gitignore (most important file in any ML repo)
cd ~/neuralcorp-setup # folder from Day 1
cat > .gitignore << 'EOF'
# Python - auto-generated, machine-specific
__pycache__/
*.pyc
.venv/
venv/
# ML model files - often gigabytes, tracked with DVC instead
*.pt
*.pkl
data/raw/
outputs/
# SECRETS - NEVER COMMIT THESE
.env
*.key
secrets.json
# OS / IDE
.DS_Store
EOF
3. Initialise, stage, and commit
git init # start tracking this folder
git status # shows your files as "untracked"
# Stage specific files - be intentional, don't use "git add ." blindly
git add .gitignore
git add hello_neuralcorp.py
git add check_environment.py
git commit -m "chore: initialise NeuralCorp ML dev environment"
git log --oneline # see your first commit
What you’ll see:
a1b2c3d chore: initialise NeuralCorp ML dev environment
4. Use the feature branch workflow
# Create and switch to a new branch in one command
git checkout -b feature/add-readme
# Create a README
echo "# NeuralCorp ML Setup" > README.md
echo "Run: conda activate ml-fundamentals" >> README.md
git add README.md
git commit -m "docs: add project README with setup instructions"
# Merge back to main
git checkout main
git merge feature/add-readme
git branch -d feature/add-readme # clean up
5. Push to GitHub
# Create a repo on github.com first (no README, no .gitignore - you already have them)
git remote add origin https://github.com/YOUR_USERNAME/neuralcorp-setup.git
git push -u origin main
What you’ll see on GitHub: your files, your commit history, your .gitignore - all visible on the web.
Common Mistakes
❌ fatal: not a git repository
✅ You're not in the right folder. Run pwd to check, then cd to the project folder and git init
❌ nothing added to commit but untracked files present
✅ You forgot git add. Run git add <file> then git commit
❌ accidentally committed .env
✅ git rm --cached .env → add .env to .gitignore → git commit -m "fix: remove accidentally committed secret"
(Do this IMMEDIATELY - secrets in git history are dangerous)
✅ Today’s One-Sentence Lesson
Git is not just a backup tool - it’s the foundation of reproducible ML, safe experimentation, and professional collaboration, and no production code ships without it.
🔗 Up Next
Day 3: Linux Terminal - the commands every ML engineer uses to navigate servers, search logs, and automate repetitive tasks.
Tags: #AI #Git #GitHub #VersionControl #MLOps #AIEngineering #Beginners