Branches and pull requests
Lesson 9 of 26 in the course “Vibe coding”. Free, with animations and a quiz.
main: the live site
A branch is a separate line of commits in a project. The main branch is usually called main. If hosting is connected to the repository, whatever is in main is the site people see right now. The bottom line in the figure is main. Hence the rule: no experiments in main. Break main, and the site is broken for everyone while you fix it.
A branch is a copy to experiment in
Example: you need an “Order ahead” button on the site of the café where you work part-time. You create a branch, a parallel copy of the project. In the figure it goes up and is called “new-button”. You can make as many commits in it as you like, here there are two. Meanwhile the live site doesn't change. Didn't work out? Just drop the branch, main won't notice a thing.
Pull request: a check before merging
A pull request, or PR, is a request to “merge my branch into main”. The PR page shows three things. The diff: which lines were added and which removed. Comments: you can discuss the changes with a friend or with AI. Automatic checks: programs run the code by themselves and put a checkmark if everything passed. In the figure the branch returns to main exactly through this box.
Preview and merge
Many hosting services build a preview for a branch: a separate copy of the site at its own link. That's the “preview link” chip in the figure. You open it on your phone, tap the new button and check that nothing broke. The live site stays untouched. All good? You hit merge: the branch's changes go into main, and the hosting updates the live site by itself.
How to work this way with an agent
Same scheme, only AI writes the code. You give the agent a task and add: “Do it in a separate branch and open a PR.” It creates the branch, makes commits and opens the PR. You open the preview, check it and say what to fix. When everything works, you do the merge yourself. That way an AI mistake stays in the branch, not on the live site.
Check yourself
- Why build a new feature in a separate branch?
Correct answer: To experiment without breaking the live site in main. A branch is a parallel copy. You can make mistakes in it freely, while main with the live site stays unchanged until merge. - What is a pull request?
Correct answer: A request to merge a branch into main, with diff and checks. A PR is a page showing what changed, with comments and automatic checks. Downloading code from GitHub is pull, a different thing. - An agent opened a PR. What do you do before merging?
Correct answer: Open the preview and check that everything works. AI makes mistakes too, so the final check is on you. The preview shows the new version before it reaches the live site.
← GitHub: your code in the cloud The terminal in 10 minutes →