Part 1 — Foundations · 18 min read
Git and GitHub from zero
Save points for your code. The one habit that stops you losing a week's work.
If you learn one thing properly from Part 1, make it this. Version control is what turns "I broke my app and I don't know what changed" into "no problem, back to yesterday". Working with AI agents that edit dozens of files at a time, it isn't optional — it's the seatbelt.
The idea, stripped of jargon
Git is a program on your computer that takes snapshots of your project. GitHub is a website that stores copies of those snapshots online. They're separate things that go together, and people muddle them constantly.
Every snapshot — a commit — records exactly what every file looked like at that moment, plus a note from you saying why. You can return to any of them, at any time, forever. Think of it as an unlimited, permanent undo that also works across many files at once.
The vocabulary
| Word | What it means |
|---|---|
| Repository (repo) | A project that Git is tracking. One project, one repo. |
| Commit | A saved snapshot with a message. The unit of "a change". |
| Stage | Choosing which changes go into the next commit. Usually: all of them. |
| Push | Send your commits up to GitHub. |
| Pull | Bring down commits from GitHub (matters once anyone else is involved, or you use two computers). |
| Branch | A parallel version where you can experiment without touching the working one. |
| main | The default branch. By convention, the version that works. |
| Merge | Folding a branch's changes back into main. |
| Pull request (PR) | A proposal to merge, with a review step. Matters once someone else is involved. |
| Clone | Download a repo from GitHub to a computer. |
| Diff | The red-and-green view of exactly what changed. You'll look at these constantly. |
Getting set up
- Make a GitHub account at github.com. Free. Use a username you wouldn't mind a future investor seeing.
- Install Git. On a Mac, typing
git --versionin the terminal will offer to install it. On Windows, get it from git-scm.com. - Tell Git who you are — this stamps your name on every commit:
git config --global user.name "Your Name" git config --global user.email "[email protected]" - Install GitHub Desktop from desktop.github.com. It's a free app that does the everyday Git operations with buttons instead of commands, and shows you diffs beautifully. Not a beginner's crutch — plenty of engineers use it for exactly this.
The loop you'll repeat forever
Roughly ten times an evening:
- Decide on one small thing to change.
- Make the change (or have the AI make it).
- Check it works in the browser. Actually click it.
- Commit, with a message describing what you did.
- Push to GitHub.
In commands, if you want them:
git status # what's changed?
git add . # stage everything
git commit -m "Add pricing section to homepage"
git push # send it to GitHub
Writing commit messages
Finish the sentence "This commit will…". So: Add email validation to signup form. Not update, fix, stuff, or asdf. In three weeks you'll be scrolling this list looking for the moment something broke, and your past self's laziness will be very annoying.
The two commands that save you
Learn these before you need them, because you'll need them at the worst possible moment.
Throw away everything since the last commit
git restore .
The AI went rogue, files are a mess, nothing works. This wipes all uncommitted changes and returns you to your last commit. It is permanent — anything not committed is gone. That's the point.
Go back to a specific earlier commit
You want the version from two hours ago. Find it in GitHub Desktop's history, or ask the AI: "Show me my last 10 commits and help me get back to the one where the signup form was working." This is normal, everyday Git use, not an emergency procedure.
Branches, and how much to care
A branch is a parallel copy where you can try something risky. If it works, merge it. If it doesn't, delete it and main never knew.
Honestly: while you're solo and pre-launch, committing straight to main often and pushing is fine. Branches earn their keep in two situations, and both will arrive:
- You have real users and main is the thing they're using. Now experiments must happen elsewhere.
- You're trying something big and speculative — a redesign, swapping a library. A branch means you can abandon it entirely with one command.
git checkout -b redesign-homepage # create and switch to a branch
# ...work, commit...
git checkout main # back to the safe version
Private or public — and why yours must be private
Every repository on GitHub is one or the other, and the choice is made when you create it. It's the most consequential setting on the whole site, and it takes two seconds to get wrong.
| Private | Public | |
|---|---|---|
| Who can read it | You, and people you invite | Everyone on the internet, forever |
| What they see | — | Every file, every commit, every commit message, every issue — the entire history, not just today's version |
| Cost | Free, unlimited repos, unlimited collaborators | Free |
| Right for | Your business. Always. | Open-source libraries, demos, your portfolio |
Make every business repository private. There's no cost saving in going public and no benefit you need at this stage. GitHub's free plan has given unlimited private repositories for years — the "private costs money" belief is simply out of date.
What a public repo actually exposes
- Secrets, within minutes. Automated bots continuously scan every new public commit for API keys. This isn't a theoretical risk — it's the single most common way small companies get an unexpected cloud bill or a data breach.
- A map of your application. Your database schema, your API routes, your permission rules, which checks happen on the server and which don't. Obscurity isn't a security strategy, but handing an attacker the blueprint makes their job dramatically easier — especially if your row level security isn't airtight.
- Real customer data you didn't mean to commit. Seed files, a CSV export used for testing, a database dump saved "just for a minute", screenshots in your README with real names in them. This is more common than leaked keys, and worse.
- Your commercial thinking. Commit messages and issues read as a roadmap: what you're building, what you abandoned, what's broken, how your pricing works.
Things people believe that aren't true
| Belief | Reality |
|---|---|
| "I have to make it public to deploy it" | No. Vercel, Netlify, Cloudflare and the rest all connect to private repositories on their free tiers. |
| "Nobody will find it — it's not linked anywhere" | Public repos are indexed and streamed to anyone watching the firehose. There is no obscurity. |
| "It's fine, my secrets are in .env.local" | Only if .env.local is in .gitignore and always was. Check the history, not just today's files. |
| "I'll clean up the history before I go public" | Rewriting history is fiddly and easy to get wrong. Far better to never be public in the first place. |
| "Private means secure" | It means not readable by strangers. Secrets still don't belong in the repo, because collaborators, contractors and future you can all read it. |
Sensible defaults
- Create it private, always. Choose the visibility on the creation screen rather than fixing it later.
- Turn on push protection in your repository's security settings. GitHub will then block a push that contains something that looks like a credential — a safety net for the mistake you'll eventually make at 11pm.
- Audit what you already have. Old practice repos and tutorial projects are frequently public and frequently contain a real key from the day you were experimenting.
- Watch your gists too. A "secret" gist is unlisted, not private. Pasting code into a public gist, a forum or a Discord is the same exposure as a public repo.
- Give contractors the least access that works, and remove them when the work ends.
What the GitHub website gives you
Beyond backup, three things you'll actually use:
- A full history you can browse from any device — every change, when, and why.
- Issues — a built-in to-do list attached to your project. Genuinely good for tracking bugs and ideas, and free.
- Connection to hosting. Services like Vercel and Netlify watch your repo and redeploy your live site automatically every time you push. This is how deployment becomes a non-event; see Getting it online.
I'm a non-technical founder who has just started using Git and GitHub. I understand that commits are snapshots, but I don't have an intuition for it yet.
Teach me by walking me through the 7 situations I'm most likely to hit in my first month — things like: I broke everything and want to go back; I committed something I shouldn't have; I'm on the wrong branch; my push was rejected; I have changes I forgot about from two days ago.
For each one:
- What it looks like from my side (the exact error or symptom I'd see)
- What's actually going on underneath
- The safe fix, step by step
- What NOT to do in a panic
Then give me a printable one-page cheat sheet of just the commands from those fixes.
Check this repository's Git setup as if you were a security-conscious senior engineer reviewing a beginner's first project.
1. Show me what's in .gitignore and tell me whether anything important is missing.
2. Check whether any secrets, API keys, credentials or .env files are currently tracked by Git, or appear anywhere in the commit history.
3. Check whether node_modules or other large generated folders are being committed.
4. Look at my last 10 commit messages and tell me honestly whether they'd be useful to me in three months. Rewrite three of them as examples of better ones.
5. Tell me whether this repo is set up so that I could safely delete my entire computer and lose nothing.
If you find a leaked secret, tell me the exact steps to deal with it — including that I need to revoke the key, not just delete the file.
I want to become confident that I can never lose work. Design a 30-minute hands-on drill for me, using a throwaway test repository, that makes me practise recovering from disaster.
Include drills for:
- Undoing all uncommitted changes
- Going back to a specific commit from earlier today
- Recovering a file I deleted by accident
- Undoing a commit I already pushed to GitHub
- Getting my whole project back onto a fresh computer from GitHub alone
For each: give me the exact steps to cause the problem deliberately, then the exact steps to recover, then how to verify I really recovered. I want to have made and fixed each disaster myself before it happens for real.
Act as a security-minded engineer reviewing my GitHub presence before I take on paying customers.
1. Tell me how to list every repository and gist I own and see which are public — including old practice and tutorial projects I've forgotten about.
2. For this repository: is it public or private, and how can I verify that myself rather than taking your word for it?
3. If any repo of mine were public, walk me through exactly what a stranger could learn from it: files, full commit history, commit messages, issues, and anything in older commits that isn't in the current files.
4. Search this repository's entire history for credentials, real customer data, database dumps, CSV exports, or anything else that shouldn't be published.
5. Tell me how to turn on secret scanning and push protection, and what each one actually blocks.
For anything you find, tell me the order to deal with it in — and be explicit that revoking a leaked key comes before deleting the file.
Read this project the way an attacker would if the repository were public, and write me a short report.
Tell me:
1. What the application does, and what the most valuable data in it is
2. My database structure, and which tables hold personal information
3. Every API route, and for each one whether permission is enforced on the server or only hidden in the UI
4. Which checks I'm relying on the browser to perform — i.e. which ones a user could simply skip
5. The three things in here that would most help someone trying to get at data they shouldn't have
6. Anything in the commit history that isn't in the current code but would still be readable
I'm non-technical, so explain what each finding would actually let someone do. Then tell me which of these I should fix regardless of whether the repo is private — because private isn't a security control.
Go to your GitHub profile and list every repository and gist. Note which are public. For each public one, ask honestly: does this contain a key, a real email address, a customer record, or anything about my business I wouldn't put on my website? Make private anything that's in doubt.
You'll know it worked when every repository connected to your business reads "Private" and you've checked the old practice projects too — those are the ones that quietly hold a real API key from the week you were learning.
Copy your repository's URL. Open a private/incognito window — so you're logged out — and paste it in.
You'll know it worked when you get GitHub's 404 page. That's what the rest of the world sees. If you see your code instead, it's public: revoke any keys that were ever committed, then change the visibility.
Turn on push protection in your repository's settings. Then deliberately try to commit a fake-but-realistic-looking credential — ask the AI for a syntactically valid dummy key in the format of a service you use — and push it.
You'll know it worked when GitHub refuses the push and tells you why. Now remove it and confirm the push succeeds. You've just installed a safety net for the night you're tired and careless.
Take the practice project from the last page. Using GitHub Desktop, or by asking your AI tool to walk you through it: turn it into a Git repository, create a .gitignore that excludes node_modules and .env.local, make your first commit, create a private repository on GitHub, and push.
You'll know it worked when you can open github.com in a browser, see your files listed, and click into one and read it. Check specifically that node_modules is not there.
With everything committed and pushed, do something destructive on purpose: delete a whole folder inside src/, and break two other files. Confirm the app is genuinely broken. Now run git restore . (or hit "Discard all changes" in GitHub Desktop).
You'll know it worked when your app runs again and every file is back. Do this twice, so it becomes muscle memory rather than something you read about. The point is the feeling: nothing you do between commits can really hurt you.
Ask your AI tool to make a small change — "add a footer with three links to every page". Before accepting or committing, open GitHub Desktop (or Cursor's source control panel) and read the diff line by line.
You'll know it worked when you can answer: how many files changed, and did it touch anything you didn't expect? If it edited files unrelated to footers, that's scope creep — exactly the thing you now want to catch before committing rather than three days later.
Spend an hour making small changes to your practice project — one visual tweak at a time. Commit after every single one, with a real message. Aim for ten commits.
You'll know it worked when your GitHub commit history reads like a diary of the evening: "Add hero heading", "Make nav sticky", "Fix spacing on mobile". That history is the habit this whole page exists to build.