Branches for Git and GitHubs
Branches are lightweight, movable pointers to commits that let you work on a feature or fix in isolation. You create one with git switch -c, combine work with git merge, or replay commits onto a new base with git rebase. Branching is the core of parallel work in Git.
Stage: Branching · Part of the Git and GitHub roadmap · Last reviewed 19 November 2026
What to learn in Branches
- Create, switch and delete branches with git switch and git branch
- Merge a feature branch and tell a fast-forward from a merge commit
- Rebase a branch onto main and explain what changes in history
- Squash several commits into one before merging
- Decide when rebase is safe and when it is not
Branches interview questions
What is a fast-forward merge?
A fast-forward merge happens when the target branch has no new commits since the feature branch split off. Git just moves the branch pointer forward to the feature's latest commit, so no merge commit is created and history stays linear.
Why is it unsafe to rebase a shared branch?
Rebase rewrites commits, giving them new hashes. If others already based work on the old commits, their histories diverge from yours and force pushes can overwrite their work. Rebase only local or personal branches.
Where Branches fits in the Git and GitHub roadmap
Branches belongs to the Branching stage (beginner level), which takes about 9 hours. Work in parallel.
Other units in this stage
Back to the full Git and GitHub roadmap