What is a Git branch?

Why Interviewers Ask This

This question tests conceptual clarity. Interviewers want to hear a precise, confident definition before moving to more complex Git & GitHub topics. It also reveals how well you can explain technical ideas to non-experts.

Answer

A branch in Git is a lightweight, movable pointer to a specific commit. Branches enable isolated, parallel lines of development — you can work on a feature, bug fix, or experiment without affecting the main codebase. When you create a new branch, Git simply creates a new pointer — no files are copied. The HEAD pointer tracks which branch you're currently on. When you commit, the current branch pointer moves forward to the new commit. Default branch: main (modern) or master (legacy). Branch commands: git branch — list all local branches (* shows current); git branch -a — list all branches including remotes; git branch feature-login — create a new branch (doesn't switch to it); git checkout feature-login — switch to a branch; git checkout -b feature-login — create AND switch (shorthand); git switch feature-login / git switch -c feature-login — modern equivalent (Git 2.23+); git branch -d feature-login — delete merged branch; git branch -D feature-login — force delete. Branches are cheap and fast — use them liberally for every feature, bug fix, and experiment.

Common Mistake

Many candidates answer correctly but can't explain the 'why'. Always be prepared to justify your answer with a concrete example or use case from your Git & GitHub experience.