Core Version Control · 8 min read · Beginner
Branches & Merging
Isolate new features on lightweight branches and merge them back into main cleanly.
What you'll learn
- Create and switch to feature branches with git checkout -b or git switch -c
- List local branches and identify the active branch
- Combine work back into main using git merge
In Git, a branch is simply a lightweight movable pointer to a commit. Creating a branch takes milliseconds and lets you build a feature or fix a bug without breaking main.
Everyday Branch Commands
git branchlists local branches (*marks the active one).git checkout -b feat/search(orgit switch -c feat/search) creates and switches to a new branch.git checkout mainswitches back tomain.git merge feat/searchintegrates commits fromfeat/searchinto your current branch.
Fill-in-the-Blank Exercise
Create and Merge a Feature Branch
Create a branch named feat-nav, then later merge it into main.
git checkout feat-nav
git checkout main
git feat-navTry It Yourself (Interactive Git Terminal)
GitBranching & Merging Lab
main
(main) $ git status
On branch main Untracked files: index.html, styles.css
Check Your Understanding
Score: 0 / 1
1. Before running git merge feat-login to merge into main, which branch should you be checked out on?
Study Workspace
Finished this lesson?
Your progress is saved locally in your browser, no account needed.