A branch in GitHub is like making a photocopy of your entire project so you can experiment without touching the original. The main branch is your clean original, and a feature branch is a marked-up copy where you make changes. When you're happy with the changes, you merge them back into the original. This is how teams work on multiple features at the same time without stepping on each other's toes.
Branches Explained — The Photocopy Analogy
Imagine you have a printed report that you're happy with. Now imagine someone wants to suggest edits — instead of scribbling on your original, you make a photocopy. They mark up the copy, and if the edits look good, you incorporate them into the original. If the edits are bad, you throw the copy away and the original is untouched. That's exactly how branches work in GitHub. Your repository starts with one branch called "main" — this is the original, clean version of your project. When you or a collaborator want to make changes (add a feature, fix a bug, test an idea), you create a new branch. This branch is an exact copy of main at that moment. All changes happen on the new branch without affecting main. When the changes are ready, you merge the branch back into main. AI tools like Lovable and V0 use branches when they connect to GitHub — Lovable syncs to the main branch, while V0 creates its own branch (like v0/main-abc123) and opens a pull request for you to review. Understanding branches is essential because every collaborative workflow on GitHub revolves around them.
Prerequisites
- A GitHub account
- A repository with at least one file
- No coding knowledge required
Step-by-step guide
Find the branch dropdown on your repository page
Find the branch dropdown on your repository page
Navigate to your repository on github.com. Look at the top of the file list — there's a dropdown button that says "main" with a branch icon next to it. This dropdown shows you which branch you're currently viewing. Think of it like choosing which photocopy of the document you're looking at. Right now, you're looking at the original (main). Click the dropdown to see all existing branches. If your repository is new, you'll only see "main" listed.
Expected result: You see the branch dropdown showing "main" as the currently selected branch.
Create a new branch from the branch dropdown
Create a new branch from the branch dropdown
Click the branch dropdown that says "main." You'll see a text field at the top with a placeholder that says "Find or create a branch..." Type a name for your new branch — for example, "add-about-page." Use lowercase letters and dashes instead of spaces (this is a GitHub naming convention). As you type, GitHub will show a blue option that says "Create branch: add-about-page from 'main'." Click that option. GitHub will create an exact copy of the main branch with the name you chose and automatically switch you to it. The dropdown will now display your new branch name instead of "main."
Expected result: The branch dropdown now shows your new branch name, and the file list looks identical to main.
Make changes on your new branch without affecting main
Make changes on your new branch without affecting main
Now that you're on your new branch, any changes you make only affect this copy. Click on any file in the list and then click the pencil icon to edit it. Make a small change — for example, add a line of text to your README. Scroll down and click "Commit changes." In the commit dialog, make sure the option says "Commit directly to the add-about-page branch" (your branch name). Click "Commit changes." The change is now saved on your branch only. To verify, click the branch dropdown and switch back to "main" — you'll see the original file without your change. Switch back to your branch and the change is there again.
Expected result: Your change is visible on the new branch but not on main.
Switch between branches to compare versions
Switch between branches to compare versions
The branch dropdown is your tool for jumping between versions. Click it and select "main" to see the original, untouched version of your project. Click it again and select your feature branch to see the version with your changes. You can do this as many times as you want — switching branches doesn't create, delete, or modify anything. It just changes which version of the files you're viewing. This is how team members can work on different features simultaneously: each person has their own branch, and switching between them shows each person's work independently.
Expected result: You can switch between main and your branch and see the differences in file content.
Understand how AI tools use branches behind the scenes
Understand how AI tools use branches behind the scenes
When you connect an AI tool to GitHub, it interacts with branches automatically. Lovable syncs your app's code to the main branch by default — every time Lovable generates a change, it pushes a commit to main. V0 takes a different approach: it creates a separate branch (like "v0/main-abc123") and opens a pull request so you can review changes before they go into main. Cursor, when used with GitHub, lets you create branches and commit to them through its built-in Git panel. Understanding this helps you know where to find your code and what's happening behind the scenes when these tools push changes.
Expected result: You understand that AI tools create and push to branches automatically as part of their GitHub integration.
Complete working example
1# Understanding Branches23## The Photocopy Analogy45- **main branch** = your clean original document6- **feature branch** = a photocopy you mark up7- **merge** = copying edits back to the original8- **delete branch** = throwing away the marked-up copy910## Common Branch Names1112| Branch Name | Purpose |13| -------------------- | --------------------------- |14| main | Production-ready code |15| add-login-feature | New login functionality |16| fix-header-bug | Fix the header layout issue |17| update-pricing-page | Redesign the pricing page |18| v0/main-abc123 | Auto-created by V0 |1920## Branch Workflow21221. Create branch from main232. Make changes on the branch243. Open a pull request254. Review and approve265. Merge into main276. Delete the branchCommon mistakes when understanding What a Branch Is in GitHub
Why it's a problem: Making changes directly on the main branch
How to avoid: Always create a new branch for changes. Main should only receive updates through merges or pull requests. This keeps your production code safe.
Why it's a problem: Using spaces or special characters in branch names
How to avoid: Use lowercase letters, numbers, and dashes only. "add-user-login" is good; "Add User Login!!!" won't work.
Why it's a problem: Creating a branch but forgetting to switch to it before making changes
How to avoid: After creating a branch from the dropdown, verify the dropdown shows your new branch name before editing files.
Why it's a problem: Letting old branches pile up without deleting them
How to avoid: After a branch is merged into main, delete it. Click the branch dropdown, then "View all branches," and delete merged branches using the trash icon.
Best practices
- Keep main as your stable, production-ready branch — never experiment on it directly
- Name branches descriptively: "add-feature-name" or "fix-bug-name"
- Create one branch per task or feature — don't mix unrelated changes in a single branch
- Delete branches after they've been merged to keep your repository tidy
- Switch to main and refresh before creating a new branch to ensure you're starting from the latest code
- If using Lovable or V0 with GitHub, check which branch the tool syncs to in its settings
Still stuck?
Copy one of these prompts to get a personalized, step-by-step explanation.
I'm a non-technical founder using GitHub for the first time. Explain branches to me using a simple analogy. Then walk me through creating a branch, making a change, and merging it back — all using the GitHub website, no terminal commands.
Frequently asked questions
Can I have multiple branches at the same time?
Yes. You can have as many branches as you want. In a team environment, each person often has their own branch for their current task. You can switch between them at any time using the branch dropdown.
Does creating a branch duplicate all my files?
Conceptually yes, but GitHub is smart about storage — it doesn't literally copy every file. It only stores the differences. So creating branches doesn't take up much extra space.
What happens if two people change the same file on different branches?
When the second branch tries to merge, GitHub will flag a "merge conflict" — it can't decide which version to keep. GitHub shows both versions and asks you to choose. For complex conflicts, RapidDev can help resolve them quickly.
Does Lovable use branches when it pushes to GitHub?
By default, Lovable syncs to the main branch with two-way sync. However, if you have branch switching enabled in Lovable's Labs settings, you can work on feature branches.
Can I delete a branch after merging it?
Yes, and you should. After merging, the branch's changes are in main, so the branch is no longer needed. GitHub even shows a "Delete branch" button after a successful merge.
What is the default branch?
The default branch is the one GitHub shows when someone visits your repository. It's called "main" by default (older repositories might use "master"). This is the branch that deployment platforms like Vercel watch for changes.
Talk to an Expert
Our team has built 600+ apps. Get personalized help with your project.
Book a free consultation