DevToolsbeginner

Git Branching

Separate lines of work that can be merged without touching main

Reviewed by Abhijith N M · 24 October 2026 · Editorial standards

The Simple VersionNo jargon

A branch is a movable pointer to a commit. Creating one is cheap; it does not copy the repository. You commit on the branch, and main stays where it was. When the work is ready, you merge or rebase it back. A merge preserves history and creates a merge commit; a rebase rewrites your commits onto a new base for a linear history. Both are fine if the team agrees and force-pushes are handled carefully.

Git Branching — Visual Breakdown

Click any step below to inspect
main (production)
feature/login
hotfix/crash
Sequence of Events
Why It Matters in Production
Short-lived branches reduce merge pain. A branch that lives for three weeks will conflict with everything else. Keep main deployable, protect it, and merge small changes often. Use feature flags for work that must ship incrementally. Rebase only your own unpushed commits; never rewrite a shared branch. Tags and release branches are for releases, not for isolating unfinished work. The branching model matters less than consistent review and a green main.
Implementation & Syntax
Bash
# Create and switch to a new branch
git checkout -b feature/user-auth

# Make changes, stage, commit
git add .
git commit -m "feat: add JWT authentication"

# Push branch to GitHub
git push origin feature/user-auth

# Merge into main (after PR review)
git checkout main
git merge feature/user-auth --no-ff

# Delete the branch (cleanup)
git branch -d feature/user-auth

Quick Concept Check

Test your understanding in 15 seconds

What does 'git checkout -b feature/x' do?

Related Concepts

Complementary topics

Written and edited by the nexGenCoders team. Spotted a mistake? Tell us and we will fix it.

Git Branching | nexGenCoders