
The first moment that stops you isn't the code. It's the question. Cloud Code finishes a chunk of work and asks, "Want me to commit this?" You type yes. Ten minutes later, the AI breaks the login page you finally got working. Now you're guessing which files it touched, and if you didn't understand what that question really meant, you're stuck. If you had saved that working version, you'd just say, "Take me back to the last version that worked," and you're back. Commit, branch, PR, every one of those questions is about the same tool. It's called Git. What follows is every Git word your AI agent throws at you in plain English, with one example app from start to finish.
Where the Code Actually Lives
Say you want to build a simple expense tracker. You open Cloud Code, ask for a first version, and pretty quickly you've got a working screen. Then you hit your first question. Where does this code actually live? You don't want it stuck on one laptop. Maybe you want to keep building on another computer later or send it to a friend.
You think, is there something like Google Drive but for code? Yes, that's GitHub. You can think of GitHub as Google Drive for code. Developers put their projects there and anyone you give access to can see the code and even edit it with you. But GitHub doesn't really work like a folder you just drag things into. Think back to school. Remember files called report_v1, report_final, report_final_final? That's version history just done by hand. GitHub is built around real version history.
Every project on GitHub is called a repository. That's a project folder that remembers every change. And the tool that builds that history on your own computer, that's Git. Here's why that matters with AI. Without Git, you ask Claude to add a feature, it breaks something that was working, and now you've got no idea which files it touched or how to get back to the version that worked. With Git, it doesn't matter how badly the AI messes up, you can always go back.
That's why before your project goes anywhere near GitHub, Cloud Code will usually ask to set up Git or it'll just run a command called git init. All that means is, "Start tracking every change in this folder."
So let's lock this in. GitHub is the website that stores your code in the cloud. Git is the tool on your computer that keeps track of every version. Step one for your app: get Git tracking the folder.
Saving a Moment That Works
You keep building and finally the login page works. You think, "That took forever. I want to save this exact moment so if the AI breaks something later, I can come right back here." That feeling, that's a commit.
Think of it like a video game. Right before the boss fight, you save manually. A commit is that save point. Once you commit, that working version is stored in your project's history. If the AI later deletes half your code or scrambles everything, you can bring back the exact state you committed.
So when Cloud Code finishes a piece of work and asks, "Want me to commit?" what it's really asking is, "This version works. Want to save it before we keep going?"
Here's the part that trips people up. A commit is not an upload. It doesn't put anything on GitHub. It just saves a snapshot on your own computer. And you don't have to wait for the AI to ask. When something works, just tell it, "This version passes my tests. Commit it and write a clear message about what changed."
Commit vs. Push
Your login page is committed. Now you want a copy online as a backup and so you can share it. Moving your saved work up to the cloud, that's called a push. Commit and push are two different things. Commit saves on your computer. Push sends those saves up to GitHub.
But before you push anything, there's one thing every vibe coder needs to know. Say your expense tracker has an API key in it for taking payments. An API key is basically a password that lets your app use someone else's service. Think of it like your house key. If you push it to a public GitHub project, you've basically taped your house key to the front door. Anyone who finds it can use it. And with a payment key, that can mean someone running up charges on your account.
Here's the difference. When the AI breaks your code, Git can save you. When a key leaks, Git can't. The fix is to cancel that key and make a new one, kind of like canceling a stolen credit card and getting a new one. Even deleting the file later doesn't help because the old version is still in the history.
GitHub does have a safety net here. It's called push protection. It's on by default for public projects and it blocks a lot of known key formats, but don't bet your keys on it. The real fix is a file called .gitignore. It's just a list that tells Git, "Don't track these files and never upload them." You don't have to remember what goes in it. Just tell Cloud Code, "Make sure the .env file, passwords, API keys, and anything secret are in the .gitignore." A .gitignore does nothing on its own, so if you think a key got committed, ask Claude to stop tracking that file and then go make a new key anyway.
Now, the first time you push, the AI is going to run some scary-looking commands. Stuff like add remote or push to origin main. Don't panic.
Remote just means the copy that lives somewhere else, on GitHub. The opposite is local, the folder on your computer. Origin is the usual nickname for your project on GitHub. And main, that's the main version of your project, the stable one. So push to origin main in plain English means, "Send the main version on my computer up to my project on GitHub."
Working with Someone Else (or Another Agent)
Your code is pushed and you send the GitHub link to a friend. Your friend thinks, "How do I get this onto my computer? And if I make changes, how do I send them back so we can build this together?" That's called a clone.
Watch out here. On GitHub, there's also a button called Download ZIP. It's not the same thing. Download ZIP just gives you a pile of files with no Git history at all. If your friend edits those files, there's no easy way to send the changes back. A clone gives them the whole project, history and all. Once you add them on GitHub as a collaborator, sending changes back is easy.
A bit later, your friend adds a new feature and pushes it to GitHub. Now you're thinking, "How do I get their latest version onto my computer?" That's a pull. It grabs the newest code from GitHub and updates your computer to match.
So here's the basic loop for building with someone else. You clone once when you first join, then you pull to grab everyone else's latest work. You commit to save your own changes, and you push to send your saves to GitHub.
Keeping Risky Work Off Main with Branches
Now you want to build something big. You want to add a database to the expense tracker so it can save each user's data. But you don't want to build it straight on main, the stable version. Because let's be honest, as a vibe coder, you're scared the AI is going to blow up everything you worked so hard on.
This is where you need a branch. Every project starts with one main line called main. That's your working, stable code. A branch is a separate line where work in progress lives. The half-finished stuff never touches the stable stuff.
You might be thinking, "I already know how to commit. Why not just let the AI work on main and go back to my last save if it breaks something?" Here's why. When the AI builds something complicated, it almost never gets it right the first time. It tries, it fails, it tries again. If all of that happens on main, your app spends that whole time half broken. Your friend wants to try the app or you spot a typo you need to fix right now, and you can't because main doesn't even run.
Picture your project folder as a magic desk. A branch is like a button next to the desk that switches between parallel worlds. Press main and the desk shows your stable code. Press the new feature branch and the desk instantly shows your draft. If the AI completely wrecks that draft, worst case, you delete the branch, switch back to main, and main is totally fine.
So here's the rule. Every time you start a new feature, step one is asking the AI to open a branch. Every commit for that feature goes on that branch. Tell your agent, "Create a new branch off main for the database feature. Commit every change to that branch and don't touch main."
Running Multiple Agents Without a Mess
Things change again. While one Cloud Code session is building the database, you want to open a second one to redesign the UI. But what if you tell two AI agents to work in the same folder at the same time? It's going to be a mess.
Remember the magic desk. Here's the problem with branches. You can switch between worlds, but you've still only got one desk, and it can only show one world at a time. If two agents share that one desk, one wants the database plans, the other wants the UI designs, and they keep fighting over what's on it. You end up with UI changes sitting on your database branch, and your Git history turns into a mess.
The fix is called a work tree. If one desk isn't enough, what's the simplest fix? You go to IKEA and buy a second desk.
A branch switches worlds on one desk, so you only see one at a time. A work tree gives you a second real desk, so both worlds exist side by side on your computer. When you ask Cloud Code for a new work tree, it creates a brand new folder for that branch. That folder is your second desk. And here's the best part: both desks share the same Git history. So Agent A sits at desk one on the database branch. Agent B sits at desk two on the UI branch. Each one works in its own folder and they never get in each other's way.
Cloud Code even has this built in. Start it with the worktree option, give it a name, and it sets up that separate desk for you. Before AI, a lot of developers barely used work trees. You've only got two hands, so you work on one thing at a time. But now as a builder, you might easily run two or three agents at once instead of waiting for one to finish before starting the next. That's exactly when you need work trees.
Pull Requests and Merging
Your agents have finished their features, each in their own space. But before any of it goes into main, you want your friend to check it on GitHub. That's called opening a PR, short for pull request. Think of it as a change proposal. Once you open it, it shows up on GitHub and everyone can review whether the changes make sense.
You don't have to write it yourself. Just tell your agent, "Open a PR for this branch. Explain what the feature does, which files changed, and how to test it." It'll write it up clearly so whoever reviews it gets it right away.
Once everyone's happy with it, there's one last step. Bringing those changes into main. That's called a merge. Someone clicks the merge button on GitHub and main on GitHub is now updated. But here's what catches almost every beginner. That merge happened on GitHub. The main on your computer, it doesn't magically update by itself. A lot of people assume the code they see in VS Code or Cursor is the latest version on GitHub. It isn't. What you see is always what's on your computer right now. GitHub can change and your computer won't know.
So every time something gets merged into main, switch back to main on your computer and tell your agent to pull. That way, your next branch starts from the latest version, not some old copy.
When Two Versions Collide
Sometimes when you merge, you get a different headache: a conflict. Say you and your friend both changed the same line in the same file, or two AI agents both edited the same core logic. Git stops and says, "Conflict." All that means is Git found two different versions of the same code and it doesn't know which one to keep.
Tools like Claude Code can read a conflict and sort it out for you. When Git hits a conflict, it leaves special markers in the file with both versions stacked on top of each other. The AI reads both sides, works out what each one was trying to do, and usually fixes it one of three ways.
First, pick a side. If your friend's version is newer or it fixed a bug in yours, the AI keeps theirs and drops the old one.
Second, keep both. You might ask, if they don't really clash, why does Git complain? Because Git is pretty literal. If two people change the same line or lines right next to each other, it calls it a conflict. Say you added an investing category at the end of the list and your friend added daily expenses at the end too. Git panics. But the AI can see you were both just adding items. It keeps both in the same menu and everybody wins.
Third, rewrite it. Sometimes jamming two pieces of logic together would just crash the app. Once the AI understands what you both wanted, it rewrites that part so both features work together.
But here's the limit. The AI doesn't know your product plans. If you and your friend made changes that clash as product decisions, the AI gets stuck. It just doesn't know which way to go. That's when your job isn't to go fix the code yourself. Your job is to make the product call. Just tell it, "Fix this conflict. Use my friend's version of the category list, but move my investing category into the advanced menu on the right." Once you're clear about what to keep and why, the AI picks the right way to merge and cleans it up.
When the AI Breaks Your Code
It's the moment every vibe coder dreads. The AI broke your code. How do you get it back? There are two common situations.
Situation one: you haven't committed yet. The AI just changed a bunch of files. You run the app and it's all wrong. Luckily, you never saved it as a commit. You're thinking, "I don't want any of this. Take me back to the last version that worked." That's called a restore. It's like loading your last save in a game, as if the AI's mess never happened. Just know that restore throws those changes away for good, so be sure. And brand new files the AI created can stick around, so ask the agent to clean those up too.
Situation two: you already committed. You saved, ran the app, and then realized that commit was a mistake. Here, the safer fix is usually a revert. A revert does not secretly delete your history. It adds a new commit that does the exact opposite of the bad one and cancels it out. That's extra safe when you're working with other people because everyone can see what happened. The mistake went in, then it got undone. Nobody's left wondering why part of the project suddenly vanished.
The best part, you don't have to memorize any of this. When the AI breaks something, just tell it, "I don't want the changes you just made. Take me back to the last working version." It'll check where things are and pick restore or revert for you.
Key Takeaways
- GitHub is Google Drive for code. Git is the tool on your computer that tracks every version.
- A commit saves a snapshot on your own computer. A push sends those saves up to GitHub. They are not the same thing.
- A
.gitignorefile keeps your API keys and passwords off the internet. If a key leaks, cancel it and make a new one. Git can't help you there. - Clone gets the whole project with history. Download ZIP gives you dead files with no way to send changes back.
- A branch is a parallel world where risky work lives. Main stays stable the whole time.
- Running multiple agents at once? A work tree gives each branch its own real folder so they never step on each other.
- A pull request is a change proposal for someone to review. A merge brings those changes into main.
- Merge conflicts mean Git found two versions of the same code. The AI can usually sort it out, but when product decisions clash, you make the call.
- If the AI breaks uncommitted work, restore throws the mess away. If you already committed, revert cancels the bad commit safely with a new one.
Git might look like a pile of alien commands, but you don't need to type them. You need to be able to direct them. You don't have to become a Git expert today. You just need to know that when Claude or Cursor asks commit, branch, PR, it's really asking you three things. Do you want to save this? Do you want a safe space to try this? And do you want someone to check this before it ships? Once you get those questions, building with AI feels a whole lot safer. Save your work with commits. Keep risky work on branches and work trees. Use PRs so somebody checks it before it ships.
