1 Hour

13. Version Control & Collaboration

Module 13: Version Control

Never lose your work again

Version control is a system that records every change made to your code over time. It's like having infinite undo history for your entire project, combined with the ability to work in parallel with a team without overwriting each other's work.

Without version control, developers used to email zip files to each other labeled final_v3_ACTUALLY_FINAL.zip. This was painful, error-prone, and didn't scale. Version control solved this entirely.

Introduction to Git

Git is the most widely used version control system in the world. Created by Linus Torvalds (the creator of Linux) in 2005, it's now the industry standard. GitHub is a website that hosts Git repositories online and adds collaboration features.

Bash
# Setting up Git for the first time
git config --global user.name 'Your Name'
git config --global user.email 'you@example.com'

Repositories & Commits

A repository (repo) is a folder where Git tracks changes. A commit is a snapshot of your project at a specific point in time — like saving a checkpoint in a game:

Bash
# Start tracking a project
git init                    # Initialize a new repository

# Stage changes for commit
git add hello.py            # Stage a specific file
git add .                   # Stage ALL changed files

# Save a snapshot
git commit -m 'Add greeting function'

# See your history
git log --oneline

# See what's changed since last commit
git status
git diff
Write Good Commit Messages

A good commit message explains WHY you made the change, not just what. Fix bug is useless. 'Fix login crash when email has uppercase letters' is valuable. Your future self will thank you.

Branching Basics

Git Branching Architecture: Parallel Feature Isolation main C1 Initial setup C2 Add auth UI git branch F1 Build API route F2 Unit tests pass feature/auth C3 Fix header bug git merge M1 Merge Pull Request v1.1.0

Branches let you work on new features or bug fixes without affecting the main codebase. When you're done, you merge your branch back:

Bash
# Create and switch to a new branch
git branch feature/user-login
git checkout feature/user-login
# Or in one command:
git checkout -b feature/user-login

# Work on your feature...
# ... make commits ...

# Switch back to main branch
git checkout main

# Merge your feature in
git merge feature/user-login

# Delete the branch (optional, cleanup)
git branch -d feature/user-login

Working in Teams — GitHub Workflow

Bash
# Clone an existing project
git clone https://github.com/user/project.git

# Connect your local repo to GitHub
git remote add origin https://github.com/you/project.git

# Push your changes to GitHub
git push origin main

# Pull latest changes from teammates
git pull origin main

The standard team workflow: (1) Pull latest changes, (2) Create a feature branch, (3) Make your commits, (4) Push to GitHub, (5) Open a Pull Request for review, (6) Merge after approval. This keeps the main branch always stable and production-ready.

Knowledge Check

Ready to test your understanding of 13. Version Control & Collaboration?

Back