Skip to content
BENIBIX Learn

Branch

Development🔀 Version ControlBranches and History

Also known as Git Branch, git switch

A line of work to one side. Try changes there while main stays safe.

Think of it like

Think of it like a side path off a main road. You can walk it, then join the road again later.

Example

Emma makes a branch called dark-mode. She tries a new look for a week, while main stays safe for everyone else.

Why it matters

Branches let many people work at once. Half-done work never breaks the main code.

Definition

A branch is a separate line of work inside one repository. You make a branch to try a feature or fix a bug without touching the main code. Commits on a branch stay there until you merge them back. The main line is often called main. Making a branch is quick and cheap in Git, so teams make one for almost every task.

Example code

console
$ git switch -c dark-mode
Switched to a new branch 'dark-mode'
$ git branch
* dark-mode
  main
A new branch, and the star shows which one you are on.

Common mistake

Letting a branch run for weeks. The longer it lives, the harder it is to merge back.

Key takeaways

  1. 1
    Work apart. Changes stay off the main line.
  2. 2
    Cheap to make. One command, one second.
  3. 3
    Merge back. Finished work joins main again.

Compare

Learn it properly