Git & GitHub Interview Question #22

What is a branch in Git?

Git Fundamentals, Repository, Working Tree, Staging, Commits & Branch Basics Junior Beginner

Quick Interview Answer

A branch is a movable reference to a commit and represents a line of development. Branches allow developers to work on features, fixes, or experiments without immediately changing another branch such as main.

Detailed Explanation

A branch is a movable reference to a commit and represents a line of development. Branches allow developers to work on features, fixes, or experiments without immediately changing another branch such as main.

Creating a branch is lightweight because Git primarily creates a new reference rather than duplicating the entire project.

Code Example

git branch feature/interview-search
git switch feature/interview-search