How Git Branches Work

A Git branch is essentially a movable reference pointing to a commit. Creating a branch is cheap because Git does not duplicate the entire project. As new commits are created, the branch reference advances.

The special reference HEAD identifies the currently checked-out position.

Branch References
Create and Switch Branches
git branch feature/login
git switch feature/login

git switch -c feature/profile
💡 git branch creates a branch without switching to it. git switch changes the current branch, and git switch -c creates and checks out a new branch.
Key Takeaways
  • Branches are lightweight references to commits.
  • Feature branches isolate work from the main line.
  • git switch -c is a convenient modern command for creating and switching.
Knowledge Check

What does a Git branch primarily represent?