Skip to content
AITermsLab
–points–day streak

What is a branch in Git?

A branch is a separate line of work in a project, where you can try changes without affecting the main version, then merge them in if they work.

Last updated

In real life

Like photocopying a recipe to try a new twist: scribble on the copy, and only update the original if the new version tastes better.

Try it yourself

The demo lets you start a branch called try-an-idea on a made-up bakery page. Commit a red button there, switch back to main and it's untouched. Merge the branch and main gets the red button too.

Your working copy (branch: main)

Rosa's Bakery

Order now

Make a change

Everything is committed.

History of the rosas-bakery repository (1 commit)

  1. a1f3c9 First version

Branches

This lesson

A branch is a safe copy to try an idea on.

Start a branch, make the button red and commit. Switch back to main: it's untouched. Merge when you're happy, or just leave the branch.

Branch vs commit

A commit is one saved step. A branch is a whole line of steps, kept apart from main, so an experiment can grow without disturbing the working version.

What is a commit in Git?

Common questions

What is main?

The main branch, usually called main, holds the version everyone agrees is good. On many sites, it's the version that's live.

What does merge mean?

Bringing a branch's changes into another branch, usually main. If two branches changed the same line differently, Git asks you which to keep.

Where you will use this

Quick check: Branch

Question 1 of 3

Why use a branch?

Why use a branch?