Branch — Explained with Examples
Branching creates diverging lines of development, allowing multiple features or fixes to proceed in isolation within the same repository.
A branch in Git is a lightweight, movable pointer to a specific commit. When you create a new branch, Git does not copy all files — it simply creates a new pointer. This makes branching nearly instantaneous and encourages frequent use.
Think of branches like sticky notes on a whiteboard. The main idea stays in the center (main branch), but you can jot down experiments, features, or fixes on separate sticky notes. If a sticky note works out, you stick it back onto the main board (merge). If not, you throw it away.
The default branch is typically called main (or master). Feature branches branch off main, receive commits, and are merged back when complete. This isolation prevents incomplete or experimental code from affecting the stable codebase.
# Create and switch to a new branch
git checkout -b feature/login
# Work on the feature
git add login.html
git commit -m "Add login form"
# Switch back to main
git checkout main
# Merge the feature branch
git merge feature/loginBranching strategies like GitFlow and GitHub Flow formalize how branches are used in teams, specifying naming conventions and lifecycle rules.
Git, Merge, GitFlow, GitHub Flow, Trunk-Based Development
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro