You are viewing a free preview of this lesson.
Subscribe to unlock all 10 lessons in this course and every other course on LearningBro.
Branches are one of Git's most powerful features. A branch is an independent line of development that lets you work on a feature, fix a bug, or experiment — all without touching the stable main codebase. When you are done, you merge the branch back in.
Internally, a Git branch is simply a lightweight pointer to a specific commit. Creating a branch costs almost nothing — it is just a new pointer. This is fundamentally different from older version control systems that copied entire directory trees.
HEAD is a special pointer that tells Git which branch you are currently on.
# List local branches
git branch
# List all branches including remotes
git branch -a
The current branch is highlighted with an asterisk.
git branch feature/login
This creates a new branch pointing at the current commit but does not switch to it.
git switch feature/login
Or, using the older syntax still commonly seen in tutorials:
git checkout feature/login
git switch -c feature/login
This is the most common workflow: create the branch and immediately start working on it.
Once you have switched to your new branch, any commits you make are recorded on that branch only. The main branch is unaffected:
# On feature/login
git add login.js
git commit -m "Add login form component"
After a branch has been merged and is no longer needed:
# Safe delete — only works if the branch is merged
git branch -d feature/login
# Force delete an unmerged branch
git branch -D feature/login
git branch -m old-name new-name
A common workflow used by teams is called feature branching:
This keeps main always in a deployable state and makes collaboration clean and reviewable.
Subscribe to continue reading
Get full access to this lesson and all 10 lessons in this course.