Skip to content
Latchkey

What Is a Git Branch?

A branch is a movable pointer to a commit, giving you a separate line of development that you can work on without affecting the main code.

Branches are how teams work on many things at once without stepping on each other. A branch is little more than a named pointer to a commit, which makes creating one nearly free. You branch off, build a feature or fix, and merge it back when it is ready and verified.

What a branch really is

A branch is just a lightweight, movable reference to a commit. When you commit on a branch, the branch pointer advances to the new commit. Because the pointer is so cheap, creating and deleting branches is instant, which encourages frequent, isolated work.

Working on a branch

You create a branch, switch to it, make commits, and later merge it back into the main line.

Branch, commit, merge
git switch -c feature/login
git commit -am "Add login page"
git switch main
git merge feature/login

Why branches matter

Branches let multiple developers and features progress in parallel. The main branch stays in a known-good state while risky or unfinished work lives elsewhere. This isolation is the foundation of pull-request workflows, where a branch is reviewed and tested before it merges.

Branches in CI/CD

CI typically runs on every branch push and on every pull request, so each branch gets its own build and test results before it merges. Pipelines often behave differently per branch, for example deploying the main branch to production while only running tests on feature branches. Filters like branch patterns let you scope which workflows run where.

Common branching pitfalls

  • Long-lived branches drift far from main and create painful merges.
  • Forgetting to delete merged branches clutters the repository.
  • Running expensive pipelines on every branch can waste CI minutes.
  • Branch protection is needed to stop unreviewed merges into main.

Key takeaways

  • A branch is a cheap, movable pointer to a commit.
  • Branches enable parallel work while keeping main stable.
  • CI runs per branch and per pull request, often with branch-specific behavior.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →