Skip to main content

What is a branch in Git?

A branch is a named pointer to a commit that represents a separate line of development.

How a branch works technically

  • a branch is not a copy of the code, but just a reference to a commit;
  • with a new commit, the branch pointer moves forward;
  • the current branch is determined by the HEAD pointer.

Example:

main → C3 feature → C2 HEAD → main

Why branches are needed

  • parallel development;
  • safe experiments;
  • feature development without affecting main;
  • convenient merging of changes (merge / rebase).

Important facts about branches

  • creating a branch is an instant operation;
  • branches are lightweight and take up almost no space;
  • deleting a branch does not delete commits if they are still referenced.

Short version for an interview

A branch is a pointer to a commit that defines the current line of development in Git.

Short Answer

Interview ready
Premium

A concise answer to help you respond confidently on this topic during an interview.