Git & GitHub,
explained like a commit history.
Every section below is written like an entry in a git log - because that's exactly what learning this tool feels like: small, ordered snapshots that build on each other. Scroll down the timeline, or jump straight to the cheat sheet.
What is Git? What is GitHub?
Two different things that people mash together constantly — worth separating on day one.
Git is version-control software that runs on your machine. It takes snapshots of your project every time you tell it to (a commit), so you can rewind, compare, or branch off from any point in history — even with no internet connection at all.
GitHub is a website built on top of Git. It hosts your repositories in the cloud and adds the social layer: pull requests, code review, issues, and a place for a team (or the whole open-source world) to work on the same codebase without emailing zip files back and forth.
Short version: Git is the engine, GitHub is one popular place to park the car. (GitLab and Bitbucket are the same idea, different lot.)
Why it's essential now
Software is written by more people, in more places, at more speed than ever.
Teams are distributed
People on the same project can be on different continents and time zones — there's no shared hard drive to edit.
Everything changes fast
Multiple features, fixes, and experiments happen in parallel; branches let all of that coexist safely.
Mistakes are inevitable
A wrong edit shouldn't mean lost work — history gives you an undo button for an entire project.
AI writes more code
As AI tools generate and edit code alongside humans, a clear diff-and-review trail matters even more.
What if Git didn't exist?
A quick look at how teams coped before, and what breaks without it.
- −Files named
final_v2_FINAL_reallyfinal.docx— because folders, not tools, were tracking versions. - −Two people editing the same file overwrite each other's work with no warning.
- −There's no reliable way to try an experiment and throw it away without risking the working version.
- −"Who changed this line, and why?" has no answer beyond asking around and hoping someone remembers.
- −Open-source as we know it — millions of strangers contributing to the same project — basically doesn't scale.
How Git actually helps: the core workflow
Every Git command you'll use daily moves a change through these four stages.
You edit files in your working directory. Running git add moves the changes you're happy with into staging — a holding area where you decide exactly what goes into the next snapshot. git commit saves that snapshot to your local repository, permanently, with a message explaining why. git push sends your commits to the remote — GitHub — where others can see and pull them.
Branches: working in parallel, safely
A branch is just a movable pointer to a commit — cheap to create, cheap to throw away.
Instead of editing main directly, you branch off, build a feature or fix a bug in isolation, and merge back when it's ready. If the experiment doesn't work out, you delete the branch — main never even knew it happened.
How GitHub turns Git into teamwork
The fork → PR → review → merge loop is how most open-source and team code ships today.
Pull Requests
A proposal: "here's a branch, please review and merge it into main." Comments, suggested edits, and approvals all happen right on the diff.
Issues
A tracked to-do or bug report, linkable to the commits and PRs that eventually resolve it — the paper trail for "why did we build this?"
Learning Git & GitHub with AI
An AI assistant is a genuinely good pairing for this subject — here's how to use one well.
Paste the error, not just the command
Git's error messages are dense but literal. Paste the full output and ask what it means before trying a fix you found online.
Ask for the “why”, not just the “how”
Instead of "how do I undo a commit", ask an AI to explain the difference between reset, revert, and restore for your exact situation — the right tool depends on whether you've already pushed.
Have it draft your commit messages
Paste a diff and ask for a clear, conventional commit message — then edit it. It's a fast way to internalize what a good message looks like.
Use it to read a diagram of a diff
Ask an AI to walk through git log --graph output line by line, or to describe in plain English what a merge conflict is actually disagreeing about.
Simulate scenarios before you risk them
"What happens if I run git reset --hard here?" is a much safer question to ask first than to find out by doing.
Cheat sheet
The commands you'll actually type, grouped by what you're trying to do. Filterable.
Setup
- git init
- Start a new repo in the current folder
- git clone <url>
- Copy a remote repo to your machine
- git config --global user.name "You"
- Set your commit author name
- git config --global user.email you@x.com
- Set your commit author email
Everyday work
- git status
- See what's changed and what's staged
- git add <file>
- Stage a file for the next commit
- git add .
- Stage everything in the folder
- git commit -m "msg"
- Save staged changes as a snapshot
- git diff
- Show unstaged changes, line by line
- git log --oneline --graph
- See history as a compact graph
Branching
- git branch
- List branches
- git switch -c <name>
- Create and move to a new branch
- git switch <name>
- Move to an existing branch
- git merge <name>
- Merge a branch into the current one
- git branch -d <name>
- Delete a branch that's been merged
Working with GitHub
- git remote -v
- List the remotes this repo knows about
- git push origin <branch>
- Send your commits to GitHub
- git pull
- Fetch + merge the latest from GitHub
- git fetch
- Download changes without merging them
Undo & rescue
- git restore <file>
- Discard unstaged changes to a file
- git restore --staged <file>
- Unstage a file, keep the edits
- git commit --amend
- Fix the message or add to the last commit
- git revert <hash>
- Undo a commit by adding a new commit
- git reset --hard <hash>
- Rewind the branch — use with care
- git reflog
- A safety net: recover "lost" commits
Important things to keep in mind
The handful of habits and warnings that save you from the worst Git afternoons.
⚠ Commit often, in small pieces
Small commits are easy to review, easy to revert, and easy to explain later. One giant commit called "stuff" helps no one, including future you.
⚠ Write commit messages for a stranger
"fix bug" tells no one anything. "Fix null pointer when cart is empty" tells the whole story without opening the diff.
⚠ `git reset --hard` deletes work
It rewinds your branch and discards changes with no confirmation. Prefer `git revert` on shared branches, and know about `git reflog` as your safety net.
⚠ Never commit secrets
API keys and passwords that reach a commit are in history forever, even if you delete the file in a later commit. Use a .gitignore and environment variables.
⚠ Pull before you push
If someone else pushed first, your push will be rejected. `git pull` (or fetch + merge/rebase) brings you up to date before you try again.
⚠ A merge conflict isn't an error
It just means two changes touched the same lines and Git wants a human to decide. Read both sides calmly — it's normal, not a sign you broke something.