🧩 Git & GitHub — The Step-by-Step Guide You’ll Wish You Had Earlier

— Issue #21 of The Artificial Newsletter

Learn how to version, back up, and publish your code like a pro (even with Jupyter Notebooks!)

🧭 Why Should You Care?

Whether you’re building a Python app, writing Jupyter notebooks, or collaborating on a research tool — Git is your best friend. It helps you:

  • Save clean checkpoints of your code

  • Go back if you mess up

  • Work with others without losing your work

  • Publish your project online via GitHub

And the best part? You only need a few commands to get started.

🔧 Step-by-Step Git & GitHub Setup (With Why Behind Each Step)

✅ Step 1: Install Git

👉 Go to https://git-scm.com/downloads and install Git for your system.

🧠 Why: This gives you the Git command-line tool so your machine can track code changes like a versioned time machine.

✅ Step 2: Configure Git (One-Time Setup)

bash

git config --global user.name "Your Name" git config --global user.email "[email protected]" 

 Why: This sets your identity for all Git projects — every commit will be tagged with your name and email.

✅ Step 3: Create a Git-Enabled Project

bash

mkdir my-project cd my-project git init 

🧠 Why: You’re telling Git, “Start watching this folder for changes.” Now it's a Git repository.

✅ Step 4: Add Your First File

bash

touch index.html   # or create it manually 

🧠 Why: Let’s add a real file Git can track. This simulates real-world work: writing code or documents.

✅ Step 5: Track the File with Git

bash

git add index.html 

🧠 Why: Git doesn’t track files automatically. You must explicitly say: “I want to track changes in this file.”

✅ Step 6: Commit (Take a Snapshot)

bash

git commit -m "Initial commit" 

🧠 Why: This saves the current version of your file(s). You can now go back to this point anytime.

✅ Step 7: Create a GitHub Repository

  1. Go to https://github.com

  2. Click New Repository

  3. Don’t initialize with a README

  4. Copy the repository URL

🧠 Why: GitHub is the online home for your project. This is where you’ll back up and share your work.

bash

git remote add origin https://github.com/yourusername/my-project.git 

🧠 Why: This sets up the connection between your folder (local) and the GitHub repo (remote).

✅ Step 9: Set the Branch Name (If Needed)

bash

git branch -m main 

🧠 Why: Git used to name the default branch master, but most modern platforms like GitHub use main.

✅ Step 10: Push Your Code to GitHub

bash

git push -u origin main 

🧠 Why: This uploads your snapshot to GitHub, making your code accessible and shareable from anywhere.

✅ Optional: Daily Workflow When You Write Python or Notebook Code

Let’s say you work on a Python script or Jupyter notebook every day.

Here’s the repeatable Git loop:

bash

git add . git commit -m "What I changed today" git push 

🧠 Why: This commits your daily progress and backs it up. If anything breaks later, you can restore earlier working versions.

📓 Bonus: Using Jupyter Notebooks?

Yes, Git works with .ipynb files too.

  • You can version notebooks the same way

  • GitHub even shows them visually

  • You can clear outputs before committing to keep diffs clean

Want help automating that? Tools like nbstripout or jupytext can help.

🎯 Final Cheat Sheet

Task

Command

Set up Git

git config --global ...

Initialize project

git init

Stage files

git add .

Save snapshot

git commit -m "message"

Connect to GitHub

git remote add origin ...

Upload to GitHub

git push -u origin main

✨ In Summary

You just learned:

  • How Git tracks your code history

  • How GitHub makes it accessible anywhere

  • Why this workflow is essential for solo and team projects

  • How to use Git with both .py and .ipynb files

You now have your own versioned, online-backed-up Python lab.

👉 Subscribe to The Artificial Newsletter