📚 Git — Version Control
Git is a tool that tracks every change you make to your code over time, so you can see the full history, go back to any previous version, and collaborate with others without overwriting each other's work.
The 10 commands you use every day
# Start tracking a project
git init # Create a new repo in current directory
git clone https://github.com/... # Copy an existing repo from GitHub
# See what's changed
git status # What files have changed?
git diff # Show the actual changes line by line
# Save a snapshot
git add . # Stage all changed files
git add file.py # Stage one specific file
git commit -m "Add login feature" # Save the snapshot with a message
# Work with remote (GitHub/GitLab)
git push origin main # Upload your commits to GitHub
git pull origin main # Download latest changes from GitHub
# Branches — work on features without affecting main code
git branch feature-login # Create a new branch
git checkout feature-login # Switch to it (or: git switch feature-login)
git checkout -b feature-login # Create AND switch in one command
git merge feature-login # Merge completed feature back to main
# History
git log --oneline # Short list of all commits
git log --oneline --graph # Visual branch historyThe mental model
Think of Git as a save-game system for your code. Every git commit is a save point — a complete snapshot of all your files at that moment. You can jump back to any save point. Branches are like parallel timelines — you can work on a new feature in a separate branch without touching the working version of your code.
What GitHub is
Git is the tool. GitHub is a website that hosts your Git repositories online so others can see them, contribute, and so your code is backed up remotely. GitLab and Bitbucket do the same thing. You don't need GitHub to use Git — but most professional code ends up there.
The most common mistakes
# Undo the last commit (keep changes in files)
git reset --soft HEAD~1
# Undo changes to a file (go back to last commit)
git checkout -- filename.py
# See what's in a commit
git show abc1234 # Replace with your commit hash
# Fix last commit message
git commit --amend -m "Better message"
# Stash work in progress (save without committing)
git stash # Temporarily hide changes
git stash pop # Bring them back
# .gitignore — tell Git to ignore certain files
echo "node_modules/" >> .gitignore
echo "__pycache__/" >> .gitignore
echo ".env" >> .gitignore # Never commit secrets/API keysgit pull downloads and immediately merges remote changes into your current branch. git fetch downloads them but doesn't merge — you review first. For solo work, git pull is fine. For teams, git fetch then review before merging is safer.git reset rewrites history — dangerous on shared branches. git revert creates a new commit that undoes the changes — safe on shared branches because history is preserved.▸ Command Line Basics
The command line (also called terminal, shell, or bash) is a text-based interface for talking to your computer. Instead of clicking icons, you type commands. It's faster, more powerful, and necessary for most programming tools. On Mac: Terminal or iTerm2. On Windows: PowerShell or WSL (Windows Subsystem for Linux). On Linux: any terminal emulator.
Navigation and file management
# Where am I?
pwd # Print working directory (current location)
ls # List files in current directory
ls -la # List all files with details
# Moving around
cd Documents # Go into Documents folder
cd .. # Go up one level
cd ~ # Go to home directory
cd / # Go to root directory
# Files and folders
mkdir my-project # Create a directory
touch README.md # Create an empty file
cp file.py backup.py # Copy a file
mv old-name.py new-name.py # Rename or move a file
rm file.py # Delete a file
rm -rf folder/ # Delete a folder (be careful — no undo!)
# Read file contents
cat file.txt # Print entire file
head -20 file.txt # Print first 20 lines
tail -20 file.txt # Print last 20 lines
less file.txt # Scroll through file (q to quit)
# Search
grep "search term" file.txt # Find text in a file
grep -r "search term" ./ # Search recursively in all files
find . -name "*.py" # Find all Python filesRunning programs
# Python
python3 script.py # Run a Python script
python3 -m venv env # Create a virtual environment
source env/bin/activate # Activate it (Mac/Linux)
pip install requests # Install a package
# Node.js / JavaScript
node script.js # Run a JS file
npm install # Install packages from package.json
npm run dev # Run the dev server
# Environment variables
export API_KEY="your-key-here" # Set a variable for this session
echo $API_KEY # Read it back📥 Docker — Containers
Docker packages your application and everything it needs to run (Python version, libraries, configuration) into a container — a lightweight, portable box that runs identically on any machine. "It works on my computer" stops being an excuse.
The key concepts
Image — a blueprint (like a class). Read-only. Built from a Dockerfile.
Container — a running instance of an image (like an object). You can run many containers from one image.
Dockerfile — the recipe that tells Docker how to build your image.
Docker Hub — a public registry of pre-built images (Python, Node, Postgres, Nginx, etc.).
A real Dockerfile for a Python app
FROM python:3.12-slim # Start from official Python image
WORKDIR /app # Set working directory inside container
COPY requirements.txt . # Copy requirements first (for caching)
RUN pip install -r requirements.txt # Install dependencies
COPY . . # Copy rest of app code
EXPOSE 8000 # Document that port 8000 is used
CMD ["python", "app.py"] # Command to run when container startsEssential Docker commands
# Build and run
docker build -t my-app . # Build image from Dockerfile (tag it "my-app")
docker run my-app # Run a container from the image
docker run -p 8000:8000 my-app # Map port 8000 on host to port 8000 in container
docker run -d my-app # Run in background (detached)
# Manage containers
docker ps # List running containers
docker ps -a # List all containers (including stopped)
docker stop container-id # Stop a running container
docker rm container-id # Delete a stopped container
# Images
docker images # List all local images
docker pull python:3.12 # Download an image from Docker Hub
docker rmi my-app # Delete an image
# Debug
docker logs container-id # See container output
docker exec -it container-id bash # Open a shell inside a running containerDocker Compose — multiple services
version: "3.9"
services:
web:
build: .
ports:
- "8000:8000"
depends_on:
- db
environment:
DATABASE_URL: postgresql://user:pass@db:5432/mydb
db:
image: postgres:15
environment:
POSTGRES_USER: user
POSTGRES_PASSWORD: pass
POSTGRES_DB: mydbdocker compose up # Start all services
docker compose up -d # Start in background
docker compose down # Stop and remove containers
docker compose logs web # See logs for the web service⚙️ CI/CD — Automated Testing & Deployment
CI (Continuous Integration) — automatically runs your tests every time code is pushed. Catches bugs before they reach production. CD (Continuous Deployment/Delivery) — automatically deploys passing code to a server. Together, they mean: push code → tests run → if tests pass → code goes live. No manual steps.
GitHub Actions — the most common CI/CD tool
GitHub Actions runs workflows defined in YAML files inside .github/workflows/. Triggered by events like push, pull request, or a schedule.
name: Test
on:
push:
branches: [main]
pull_request:
branches: [main]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4 # Download repo code
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Install dependencies
run: pip install -r requirements.txt
- name: Run tests
run: pytest # Or: python -m pytest
- name: Run linter
run: ruff check . # Or: flake8Key concepts
Workflow — the full automated process (defined in a YAML file).
Job — a set of steps that run on one machine. Multiple jobs can run in parallel.
Step — a single task within a job (run a command, or use a pre-built action).
Action — a reusable piece of CI/CD logic (like actions/checkout which clones your repo).
Runner — the machine that runs the job. GitHub provides free Linux, Windows, and Mac runners.
Other CI/CD tools
GitLab CI/CD, CircleCI, Jenkins, Travis CI, and Bitbucket Pipelines all follow the same concepts — trigger → jobs → steps — with different YAML syntax. GitHub Actions is the easiest starting point if your code is on GitHub.