Skip to main content

Sign in

Save your progress and access it from any device.

Or with email

Don't have an account?

Privacy policy

Git Branching Workflow: branch, merge, rebase and more

Branches are what make Git powerful. Learn how to create, switch, merge and rebase branches — and pick the right strategy for your team.

Hub page

This page is your map to Git branching. Each section links to a detailed guide so you can dive deeper into any command.

What are branches?

A branch in Git is a lightweight pointer to a specific commit. When you create a branch, Git does not copy any files — it simply creates a new pointer. This makes branching nearly instantaneous, even in large repositories. Think of branches as parallel timelines: the main branch is your stable timeline, and feature branches are alternate timelines where you build and test without affecting production code.

Every Git repository starts with a single branch (usually main or master). From there, the branching model you adopt determines how your team collaborates. The rest of this page covers every command you need to master that workflow.

Create and switch branches

Three commands let you create and navigate branches. git branch manages branches, git switch moves between them, and the legacy git checkout does both (and more).

git branch

git branch is the core command for managing branches. Run it without arguments to list local branches, add a name to create one, or use -d to delete a branch that has been merged. It never switches your working directory — it only manages pointers.

git switch

Introduced in Git 2.23, git switch is the dedicated command for changing branches. Use git switch -c name to create and switch in one step. It is clearer than checkout because it does one thing: move between branches.

git checkout (legacy)

Before Git 2.23, git checkout was the only way to switch branches. It still works and you will see it in older tutorials, but it also restores files and detaches HEAD — making it easy to misuse. For branch switching, prefer git switch.

Merge strategies

Once your feature branch is ready, you need to integrate it back. Git offers three main strategies: merge for a faithful history, rebase for a linear history, and cherry-pick for grabbing individual commits.

git merge

git merge integrates one branch into another. If the branches have diverged, Git creates a merge commit with two parents — preserving the complete history. If no divergence exists, Git performs a fast-forward merge (no extra commit needed).

git rebase

git rebase takes every commit on your branch and replays it on top of another branch. The result is a perfectly linear history with no merge commits. It is powerful but rewrites commit hashes — so never rebase commits that have been pushed to a shared branch.

git cherry-pick

git cherry-pick copies a single commit from one branch to another. It does not merge or rebase — it creates a new commit with the same changes. Use it when you need a specific fix without pulling in an entire branch.

Merge vs Rebase: which to choose?

This is one of the most common Git debates. Use the decision cards below to pick the right strategy, then check the comparison table further down for a side-by-side overview.

Choose merge when...

You want a complete history

The branch has been pushed or shared with others. You want every contributor's work to remain visible in the log. Merge commits act as milestones that show when features were integrated.

Choose rebase when...

You want a clean, linear history

The branch is local and has not been pushed. You want a straight line of commits without merge nodes. Rebase keeps the log easy to read and makes git log --oneline a pleasure.

Choose cherry-pick when...

You need a single commit

A critical fix is on another branch and you only need that one commit. Cherry-pick avoids pulling in unrelated work. Ideal for hotfixes and backports.

Avoid rebase when...

The branch is shared

If you have already pushed your branch and others are working on it, rebasing rewrites history and creates diverging commits. This leads to confusion and duplicate work. Use merge instead.

Handle merge conflicts

A merge conflict occurs when two branches modify the same line of the same file. Git pauses and marks the file with <<<<<<<, =======, >>>>>>> markers. Open the file, choose the version you want (or combine both), remove the markers, then stage and commit. For a detailed walkthrough, see our guide on resolving merge conflicts.

Branch naming conventions

Consistent branch names make your repository easier to navigate. Most teams use a prefix/description pattern. Here are the most common prefixes:

PrefixPurposeExample
feature/New feature or enhancementfeature/user-auth
bugfix/Bug fix (non-urgent)bugfix/login-redirect
hotfix/Urgent production fixhotfix/security-patch
release/Release preparationrelease/v2.1.0
chore/Maintenance or toolingchore/update-deps

Use lowercase letters, hyphens instead of spaces, and keep names short but descriptive. A good branch name tells your teammates what you are working on at a glance.

Comparison: merge vs rebase vs cherry-pick

Criteriagit mergegit rebasegit cherry-pick
History styleNon-linear (merge commits)Linear (no merge commits)Copies individual commits
Rewrites historyNoYesNo
Safe for shared branchesYesNoYes
IntegratesEntire branchEntire branchSingle commit
Conflict resolutionOnce per mergePer replayed commitPer picked commit
Best forTeam collaborationLocal cleanup before pushHotfixes and backports
A

GitQuest is created by Anaïs (nouvelle fenêtre), web developer and head of education, specializing in tech training and digital accessibility.

Questions about Git branching workflows

Master branching with practice

GitQuest turns branching theory into hands-on exercises. Create branches, resolve conflicts and rebase in a simulated terminal.

Start practicing now