Skip to content
Guest
Learn Git · Course Syllabus Show lessons
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 branch lists local branches (* marks the active one).
  • git checkout -b feat/search (or git switch -c feat/search) creates and switches to a new branch.
  • git checkout main switches back to main.
  • git merge feat/search integrates commits from feat/search into 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-nav

Try 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.

Search courses, lessons, and references

Type to search across all courses, lessons, and quick references.

Press Esc to close Powered by Pagefind