Git and GitHub for Beginners: The Undo Button for Your Whole Project
If you build with AI, git is the single most useful thing you can learn — it lets you save your project at good moments and go back when the AI breaks something. What git and GitHub are, the six commands you need, and a simple routine to follow.
Here's a situation every person building with AI hits eventually. The app was working. You asked for one more change. Now three things are broken, the AI's attempts to fix them made it worse, and you can't remember what the working version looked like.
Git is the solution. It's the most valuable tool you can learn as a beginner — more than any programming language — because it turns "I broke everything" into "let me go back to ten minutes ago."
Git vs GitHub
They're related but different:
- Git is a tool that runs on your computer. It keeps a history of your project, so you can save snapshots and go back to any of them.
- GitHub is a website that stores your git history online. It's a backup, a place to share code, and where you collaborate. (GitLab and Bitbucket are alternatives.)
Git works without GitHub. But using both means your project's entire history is backed up somewhere other than your laptop.
The key idea: commits are save points
In a video game, you save before the boss fight so you can try again if it goes wrong. In git, that save is called a commit.
A commit is a snapshot of your whole project at one moment, with a short message describing what changed: "Add sign-up form," "Fix checkout total." Your project's history is a list of these save points, and you can return to any of them.
The six commands you need
You'll do most of this through buttons in your editor or AI tool, but here are the underlying commands.
git init # start tracking a project (once per project)
git status # what has changed since the last save?
git add . # include all current changes in the next save
git commit -m "Add sign-up form" # make the save point
git log --oneline # list your save points
git push # upload your save points to GitHub
That's the core loop: change things → git add → git commit → git push.
Going back
When something breaks and you want to undo:
- Throw away changes you haven't saved yet:
git restore .— puts every file back to the last commit. (These unsaved changes are gone for good, so be sure.) - See what changed:
git diffshows exactly which lines are different from the last save point. - Go further back: git can restore any file, or the whole project, to any earlier commit. How to Undo Almost Anything in Git covers every situation.
The more often you commit, the smaller any mistake is. If your last commit was five minutes ago, the worst case is losing five minutes.
Branches: try things without risk
A branch is a separate line of work. Your main, working version lives on a branch called main. When you want to try something — a new feature, a risky change — you create a new branch:
git switch -c try-new-design
Now you can change anything. If it works out, you merge it back into main. If it doesn't, you switch back to main and it's untouched:
git switch main
For people building with AI, this is a superpower: let the AI experiment on a branch, and main always stays working. On GitHub, merging a branch usually happens through a pull request — see What Is a Pull Request?.
Setting it up
- Create a GitHub account at github.com.
- Install git (it's often already installed on Mac and Linux; on Windows, install Git for Windows).
- Connect a project: create a new repository on GitHub, then follow the instructions it shows to push your existing project. Many AI builders — Lovable, Bolt, v0, Replit — have a "Connect to GitHub" button that does this for you.
- Set up SSH keys so you don't type passwords — SSH Keys Explained walks through it.
What NOT to put in git
Git remembers everything, forever — including mistakes. Never commit:
- Secret keys and passwords. Put them in a
.envfile and make sure.envis listed in a file called.gitignore, which tells git to ignore it. (What Is an Environment Variable?) node_modulesor other downloaded dependencies — they're huge and can be re-downloaded.- Large files like videos or database dumps.
If you accidentally push a secret to GitHub, deleting it in a new commit isn't enough — it's still in the history. Change the secret (get a new key) immediately.
A simple routine
- Before asking the AI for a big change: commit. "Working version before adding payments."
- When something works: commit. Small, frequent save points beat big ones.
- For anything risky: make a branch first.
- At the end of every session: push to GitHub.
Follow those four and you'll never lose more than a few minutes of work, no matter what the AI does.
EasySpawn connects to GitHub and keeps it as the home of your code: Claude Code works on branches, commits, pushes, and opens pull requests for you — so every change has a save point. See how it works or join the waitlist.
Related: What Is a Pull Request? · The Terminal for Complete Beginners · How to Write Good Commit Messages · Git Branches Explained · What Is .gitignore?
Keep reading
What Is React? A Beginner's Guide to the Library Behind Most AI-Built Apps
Lovable, Bolt, v0, and Claude Code all tend to produce React. What React is, what components, props, and state mean, how to read a .jsx file, what hooks like useState and useEffect do, and the React mistakes AI tools make most often.
What Is Node.js? JavaScript Outside the Browser, Explained
Node.js lets JavaScript run on servers and on your computer, and it's behind npm, most AI-built backends, and tools like Claude Code's ecosystem. What Node.js is, what it's used for, LTS versions, how to install it properly, and the errors beginners hit first.