Prefer branching from main (or master), not from another feature branch β€” unless explicitly required

Abhinav KumarAbhinav Kumar
2 min read

🚦 The Rule

β€œAlways create a new branch from main (or master), not from another feature branch.”


❓ Why This Rule Exists

  1. Avoid Carrying Unrelated Changes

    • If you branch off from another feature branch, your new branch will contain:

      • Your changes + all the unfinished/unmerged work from that feature branch.
    • This makes your branch β€œdirty” with unrelated commits.

πŸ”΄ Example:

    main β†’ feature-A
                ↳ feature-B (created from feature-A)

Now feature-B includes all of feature-A’s code, even if feature-A is not merged yet.
If feature-B gets merged first, it might pull in feature-A’s half-done work.


  1. Cleaner Pull Requests (PRs)

    • When you make a PR from feature-B, reviewers see changes from both feature-A + feature-B.

    • This makes code review confusing, as reviewers can’t easily tell what belongs to your task.


  1. Avoid Merge Conflicts Later

    • If feature-A changes a lot before merging, then feature-B (branched off from it) will constantly face merge conflicts.

    • If you branched from main, you only deal with conflicts once when merging your own work.


  1. Independent Features

    • Features should be independent. If feature-B actually depends on feature-A, that’s a special case β€” but normally, features should stand alone and merge cleanly into main.

  1. Predictable Git History

    • Branching from main keeps history simple:

      • main β†’ feature-A

      • main β†’ feature-B

    • No accidental β€œchaining” where branches depend on each other unnecessarily.


βœ… Correct Workflow Example

main
 β”œβ”€β”€ feature-A
 └── feature-B

Both start from main.
Each PR only shows its own changes.
They can be merged in any order.


⚠️ Wrong Workflow Example

main
 └── feature-A
        └── feature-B
  • feature-B contains code from both A + B.

  • If feature-A is delayed, feature-B is blocked.

  • Code reviews and merges become messy.


πŸ§‘β€πŸ’» Real-Life Example

Imagine you’re building an app:

  • feature-A = Add Login Page

  • feature-B = Add Dashboard

If you make feature-B from feature-A, then your dashboard branch also has the login page (even if not ready).
If the team merges feature-B first, the login code sneaks in too, even though it’s incomplete. That’s risky.


πŸ“Œ Exceptions (When You Might Branch Off Another Feature)

  • When one feature truly depends on another (e.g., feature-B requires feature-A to exist).

  • In that case, you branch from feature-A, but you should note in your PR:

    β€œThis branch depends on feature-A β€” merge feature-A first.”


πŸ‘‰ In short:
Branch from main to keep branches clean, independent, and reviewable. Only branch from another feature if it’s a hard dependency.


0
Subscribe to my newsletter

Read articles from Abhinav Kumar directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Abhinav Kumar
Abhinav Kumar

πŸŽ“ B.Tech CSE | πŸ‘¨β€πŸ’» Learning DSA & C++ | πŸš€ Building projects & writing what I learn | πŸ“š Currently solving LeetCode & exploring Git/GitHub