A properly initialized Git repository for an AI project, with a .gitignore, a commit history showing meaningful messages, and your first remote push to GitHub.
Why Version Control Matters for AI
AI projects are uniquely messy. You'll experiment with different prompts, swap models, tune parameters, and refactor code constantly. Without Git, you're flying blind — one wrong change and you can't get back to the version that worked.
Git gives you a time machine: every commit is a snapshot you can restore. It also enables collaboration, deployment pipelines, and professional workflows that employers expect.
The rule: If you wrote code today and didn't commit it, you don't own it. Disk failures, accidental deletes, and "what did I change?" moments are all solved by Git.
Install Git
# Mac (if not installed)
xcode-select --install
# Or via Homebrew
brew install git
# Verify
git --version
# git version 2.43.0
# Set your identity (one-time setup)
git config --global user.name "Your Name"
git config --global user.email "[email protected]"Initialize a Repo and Make Commits
Every Git project starts with git init. This creates a hidden .git folder that stores all history. You then stage changes and commit them with a message.
# Create an AI project folder
mkdir my-ai-project && cd my-ai-project
git init
# Initialized empty Git repository in .../my-ai-project/.git/
# Create a Python file
echo "# My AI Project" > README.md
touch main.py
# Check what Git sees
git status
# Untracked files: README.md, main.py
# Stage all files
git add .
# Commit with a message
git commit -m "Initial project setup"
# [main (root-commit) a1b2c3d] Initial project setupCommit message rule: Use the imperative mood. "Add error handling" not "Added error handling". Future-you will thank present-you.
The .gitignore File — Critical for AI Projects
AI projects have files you never want in version control: API keys, model weights, virtual environments, and output files. The .gitignore file tells Git to skip them.
# Python environment
venv/
.venv/
__pycache__/
*.pyc
# Secrets — NEVER commit these
.env
*.env
secrets.json
# AI/ML artifacts
*.pkl
*.h5
models/
checkpoints/
outputs/
# Data (usually too large)
data/raw/
*.csv
# OS files
.DS_Store
Thumbs.db
# IDE
.cursor/
.vscode/settings.jsonWarning: If you accidentally commit a .env file with your Anthropic API key, rotate the key immediately. Even if you delete it in a later commit, it exists in Git history.
Push to GitHub
GitHub stores your repo in the cloud. You get backup, collaboration, and the ability to deploy from it. Create a repo on github.com (no README, no .gitignore — you have those locally), then connect it:
# After creating repo on github.com
# Connect your local repo to GitHub
git remote add origin https://github.com/yourusername/my-ai-project.git
# Rename default branch to main (best practice)
git branch -M main
# Push your commits to GitHub
git push -u origin main
# Branch 'main' set up to track remote branch 'main' from 'origin'.
# Future pushes are just:
git pushThe -u flag sets the upstream tracking, so future git push and git pull commands know where to go without extra arguments.
What You Learned Today
- Installed Git and configured your identity
- Created a repo with git init and made meaningful commits
- Built an AI-project .gitignore that protects secrets and ignores artifacts
- Connected your local repo to GitHub and pushed your first commit
Go Further on Your Own
- Add a .env.example file that shows required env vars without real values
- Write a meaningful README.md that explains what the project does and how to run it
- Make 3 more commits practicing good commit messages
Nice work. Keep going.
Day 2 is ready when you are.
Continue to Day 2Want live instruction and hands-on projects? Join the AI bootcamp — 3 days, 5 cities.