Video in progress
What is a branch in Git, really? Why is creating a new branch so fast?
A branch is a named pointer to a single commit. It is a tiny file holding just the commit hash, so creating a branch copies no files and happens instantly.
📖 Answer
Many people picture a branch as "a separate copy of the code". It is not.
git switch -c feature/login
cat .git/refs/heads/feature/login
# 3f9a2c1e... - just a commit hash
When you make a new commit, Git moves this pointer to the new commit. The other branches stay where they were.
That is why creating many branches in Git is cheap: a separate branch for every task and every experiment is normal practice. In older VCSs branches were expensive, so people avoided them. Git has no such problem.
Sign up to mark studied questions and save your progress.