Git and GitHub
Learn how version control tracks every change you make — and how to collaborate with developers anywhere in the world.
What Is Git?
Git is a version control system. It tracks every change you make to your code — what you added, what you deleted, what you broke. If you mess something up, you can rewind to a working version. No more "final_FINAL_v3_REALFINAL.js" files.
Think of it like Google Docs history, but for code. Every time you save a checkpoint, Git remembers exactly what changed. You can go back in time, compare versions, or try new ideas without risking your working code.
Without Git
- ✗ One person can work at a time on a file
- ✗ No way to undo a bad change
- ✗ Merging two people's work means copy-pasting manually
- ✗ Every collaborator needs the latest file via email or Dropbox
With Git
- ✓ Multiple people work on the same project simultaneously
- ✓ Revert to any previous version instantly
- ✓ Git automatically merges changes intelligently
- ✓ Everyone stays in sync through a shared repository
Git vs GitHub
Git and GitHub are not the same thing. Git is the tool — a version control program that runs on your computer. GitHub is a hosting service — a website where you store your Git repositories online so others can access them.
You can use Git without GitHub. But without a hosting service, your collaborators need direct access to your machine. GitHub makes it easy to share code with the world.
Why It Matters for You
Every professional development team uses Git. Whether you are building a side project or joining a company, knowing Git is non-negotiable. It is the shared language of software collaboration.
The Four Core Git Commands
You can do almost everything in Git with four commands. Once you understand these, the rest clicks into place.
git clone
Download a project from GitHub to your computer. You get the entire codebase and its full history in one command. Use this once per project.
git add
Stage your changes before committing. You can stage all changes at once or pick specific files. Think of it like selecting which photos to include in a photo album.
git commit
Take a snapshot of your staged changes. Every commit has a message describing what changed. This is your save point — you can always come back to it.
# Download a project from GitHub git clone https://github.com/user/repo-name.git # Stage a specific file git add index.html # Stage all changed files git add . # Commit with a message describing your change git commit -m "Fix: corrected typo in hero heading" # Push your commits to GitHub git push origin main
A Real Git Session
Here is what a typical coding session looks like with Git. You are building a landing page, and you make three commits as you go.
# Commit 1 — Initial structure git add index.html git commit -m "Add: initial HTML structure with hero section" # Commit 2 — Add styling git add styles.css git commit -m "Add: dark theme styles and responsive layout" # Commit 3 — Fix a bug git add index.html git commit -m "Fix: corrected button link on mobile"
Branch: Trying Something New
Branches let you work on new features without touching your working code. Create a branch, experiment, and if it works — merge it back in. If it breaks, delete the branch and nothing is affected.
# Create and switch to a new branch git checkout -b add-newsletter-form # Do your work, commit as usual... git add form.html git commit -m "Add: newsletter signup form" # Switch back to main branch git checkout main # Merge your new branch into main git merge add-newsletter-form
Knowledge Check
Test what you learned about Git and GitHub.
3 Questions
What is the difference between Git and GitHub?
What does a git commit represent?
What is the purpose of branching in Git?