A branch is a label on a commit: a file in .git that holds one hash. Making one copies nothing, so it's instant, and teams make one for every feature or fix.
git branch ← list branches; * marks the one you're on
* main
git branch feature/faq ← make a branch at the commit you're on
git branch
feature/faq
* mainmain and feature/faq are two labels on the same commit. Both files hold the same hash:
ls .git/refs/heads
feature main ← the / in feature/faq made a folder
cat .git/refs/heads/main
8cf76374bedc4214b45da16f8e1f57e334819e87
cat .git/refs/heads/feature/faq
8cf76374bedc4214b45da16f8e1f57e334819e87A branch can start at any commit: put the commit after the name. HEAD means the commit you're on, HEAD~1 the one before it, HEAD~2 two back:
git branch hotfix HEAD~1
git log --oneline --all ← --all shows every branch, not only yours
8cf7637 (HEAD -> main, feature/faq) Add prices
27abc14 (hotfix) Start the shopObjectives
- Make a branch for the cart at the latest commit.
- Make a branch that starts one commit back.
- Find the file that holds a branch.