Save your work, undo mistakes, and collaborate — without memorizing commands.
Imagine Google Docs version history — every time you edit a document, Google saves a snapshot. You can see what changed, who changed it, and go back to any previous version.
Git is the same thing, but for your code.Every time you save a snapshot (called a "commit"), Git remembers exactly what your project looked like at that moment. You can go back to any save point whenever you want.
Analogy: Git is a time machine for your code. Each commit is a photograph of your entire project at one moment in time. You can flip back through the photo album whenever you need to.
Your AI tool generates code for you. Most of the time it works great. But sometimes one bad prompt can mess up your entire project — your layout breaks, your data disappears, or your pages stop loading.
Without Git, you have no way to go back.You would need to remember what your code looked like before and manually undo every change. With Git, you just tell it "go back to my last save point" and everything is restored.
Without Git
One bad AI prompt breaks your nav bar. You try to fix it, but now the footer is broken too. You spend 2 hours trying to get back to where you started.
With Git
One bad AI prompt breaks your nav bar. You run one command and your project is back to the way it was 5 minutes ago. Total time: 10 seconds.
Git has hundreds of commands, but you only need five. Your AI tool runs them for you most of the time — but knowing what they do helps you understand what is happening.
git commit
Takes a snapshot of your project right now. You add a short message describing what changed, like "Added contact page" or "Fixed broken nav bar."
Analogy: Saving your video game
git push
Sends your saved snapshots to GitHub so they are backed up online. If your computer breaks, your code is safe.
Analogy: Uploading your save file to the cloud
git pull
Grabs the newest version of the code from GitHub. Important if someone else (or you on another computer) made changes.
Analogy: Downloading the latest version
git branch
Creates a separate version of your project where you can try risky changes. If it works, you merge it back. If not, you delete the branch.
Analogy: Making a copy to experiment with
git checkout
Jumps to a different branch or goes back to a previous save point. This is your "undo" button for big mistakes.
Analogy: Switching between versions
A commit is like saving your progress in a video game. Each save point has a short description so you know what happened at that moment.
Good commit messages matter. When you need to go back, you will scan through your save points looking for the right one. Clear messages help you find it fast.
Good commit messages
Bad commit messages
Tip: Most AI tools write commit messages for you automatically. But if your tool asks you for a message, describe what changed in a few words. Future-you will thank you.
Imagine you have a working website. You want to try adding a completely new feature — maybe a dark mode toggle or a payment system. But you are not sure it will work, and you do not want to break what you already have.
A branch is like making a photocopy of your entire project. You work on the copy. If it works out, you merge the copy back into the original. If it does not work, you throw the copy away. Your original stays untouched either way.
How branches work in practice
1. Your main project lives on a branch called main
2. You create a new branch called add-dark-mode
3. You experiment freely on that branch — nothing affects main
4. If it works, you "merge" the branch back into main. If not, you delete the branch.
Git lives on your computer. GitHub is the cloud version. Think of it like the difference between a Word document on your desktop vs. the same document saved in Google Drive.
Push
Upload your saves to GitHub
Pull
Download the latest from GitHub
Clone
Download a full copy of a project
Analogy: GitHub is Dropbox for code. Your project is saved locally on your machine and backed up in the cloud. If your laptop is stolen, your code is safe on GitHub.
This is the most important section. When an AI prompt breaks your project, here is how to get back on track.
"I just broke something and want to undo my last change"
If you have not committed yet, you can throw away all uncommitted changes and go back to your last save point.
"I just made changes that broke my project. How do I undo all uncommitted changes and go back to my last commit? I'm using [your AI tool]. Please walk me through it step by step."
"I want to go back to how things were yesterday"
Git keeps a log of every commit. You can look through the log and jump back to any point.
"I need to go back to a previous version of my project from earlier today or yesterday. Show me my recent commits and help me check out the right one. Please explain each step in plain English."
"I want to keep my changes but set them aside for now"
Git stash saves your changes temporarily without committing them, like putting your work in a drawer to come back to later.
"I have uncommitted changes that I want to save temporarily but not commit yet. How do I use git stash to set them aside and get them back later? Please explain step by step."
The good news: most AI coding tools handle Git for you behind the scenes. Here is what each tool does automatically.
Claude Code
Automatically creates commits with descriptive messages as you work. You can see the full Git history and ask Claude to undo changes, create branches, or push to GitHub.
Cursor
Has a built-in source control panel that shows your changes. You can commit, push, and pull right from the sidebar. Cursor also shows inline diffs so you can see what the AI changed.
Bolt, Lovable, Replit
These browser-based tools save versions automatically. They have built-in version history or "undo" features. Some can connect to GitHub for more advanced workflows.
Some files should never be saved to Git. Your secret passwords, massive dependency folders, and local settings files — these should stay on your computer only.
A .gitignore file tells Git to ignore specific files.It is like a "do not track" list. Anything listed in this file will not be committed or pushed to GitHub.
.env.local
Your secret passwords and API keys. Never share these.
node_modules/
Thousands of dependency files. Way too large to track. They get reinstalled automatically.
.next/ or dist/
Generated build files. These get recreated every time you build your project.
"Check my .gitignore file and make sure it includes .env.local, node_modules, and .next. If I do not have a .gitignore file, create one with all the standard entries for a Next.js project."
You ask your AI tool to redesign your entire homepage. It makes changes across 15 files and now nothing looks right. Instead of trying to manually undo each change, you use Git to jump back to your last commit — the version before the AI made changes. Your whole project is restored in seconds.
Build this with AI
"I asked my AI tool to redesign my homepage and it broke everything. Help me use Git to go back to my last working version. Show me my recent commits and help me restore the right one. I'm using [Claude Code / Cursor / other tool]."
These error messages look scary, but they are easy to fix. Here is what each one means.
Your branch is behind 'origin/main'
What it means: Someone else (or you on another computer) pushed changes to GitHub. Your local copy is outdated.
How to fix it: Run git pull to download the latest changes before continuing.
Merge conflict in [filename]
What it means: Two people (or you and your AI tool) changed the same lines in the same file. Git does not know which version to keep.
How to fix it: Ask your AI tool to resolve the conflict. Say: "I have a merge conflict. Help me pick the right version."
Detached HEAD
What it means: You are looking at an old version of your project but not on any branch. It is like standing in a museum looking at an old painting — you can see it but you are not "working" on it.
How to fix it: Run git checkout main to go back to your main branch.
Failed to push — rejected
What it means: GitHub has changes that you do not have locally. You need to download them first before uploading yours.
How to fix it: Run git pull first, then try git push again.
Copy these prompts and paste them into your AI tool whenever you need Git help.
Set up Git for a new project
"I just created a new project. Help me initialize Git, create a .gitignore file with the right entries for a Next.js project, connect it to a new GitHub repository, and push my first commit. Walk me through every step."
Create a branch for a new feature
"I want to try adding [describe feature] to my project without breaking what I have now. Help me create a new Git branch, make the changes there, and then merge it back into main when it works."
Understand what changed
"Show me what files have changed since my last commit and explain what each change does in plain English. I want to understand what my AI tool modified before I commit."
Do I need to memorize Git commands?
No. Your AI tool handles Git for you most of the time. But understanding what Git does helps you fix problems and avoid losing work. Think of it like knowing how a car works — you do not need to be a mechanic, but knowing what the gas pedal does helps.
What happens if I forget to commit?
Nothing bad happens immediately. But if you make a mistake later, you will not be able to go back to that point. It is like playing a video game without saving — if you lose, you start over from your last save.
Can Git break my project?
Git itself will not break anything. It only tracks and saves changes. If you accidentally run a destructive command, Git usually has a way to undo it. When in doubt, ask your AI tool for help before running any Git command you do not understand.
Do I need a GitHub account?
You do not strictly need one, but it is highly recommended. GitHub is free and gives you a cloud backup of your code. If your computer dies, your code is safe on GitHub. It is also required if you want to deploy to Vercel or collaborate with others.