Update Git branches from master
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
Keeping a feature branch current with master is routine Git hygiene that reduces late merge surprises. The two main approaches are merge and rebase, and each has different history and collaboration implications. Choosing intentionally, instead of by habit, prevents avoidable conflicts and force-push incidents.
Prepare the Branch Before Updating
Start with clean local state.
If you have uncommitted work, commit it or stash it first.
Then fetch remote refs.
Fetching first keeps updates explicit and avoids operating on stale branch tips.
Method 1: Merge master Into Feature Branch
Merge preserves exact branch history and creates a merge commit when needed.
If conflicts appear, resolve files, add them, and complete merge.
Then push branch.
Use merge when shared branch history should remain explicit or when team policy discourages rewriting commits.
Method 2: Rebase Feature Branch Onto master
Rebase replays feature commits on top of the latest master, creating a cleaner linear history.
During conflicts:
After successful rebase, push with force-with-lease.
--force-with-lease is safer than plain force because it checks remote branch state first.
Merge or Rebase Decision Guide
Use merge when:
- Branch is shared by multiple developers.
- You want to preserve exact integration points.
- Team prefers non-rewritten history.
Use rebase when:
- Branch is personal or tightly coordinated.
- You want a linear review history.
- You can safely force-with-lease after rewrite.
The right choice depends on branch ownership and collaboration model.
Conflict Resolution Practices
Conflict quality matters more than conflict speed.
Recommended workflow:
- Resolve one file at a time.
- Run tests after each logical conflict group.
- Re-read final diff to ensure intended behavior.
Useful commands:
This helps verify you did not accidentally drop necessary changes while resolving conflicts.
Keep Branches Fresh to Minimize Pain
Large divergence from master creates harder conflict sessions. Update frequently rather than waiting until merge day.
A practical cadence for active branches is daily fetch and periodic sync from master.
Frequent small syncs are easier to debug than one massive catch-up.
Special Case: master Renamed to main
Many repositories now use main instead of master. The commands are identical except branch name.
Check default branch with:
Keep team docs and scripts aligned with actual default branch to avoid confusion.
If your repository enforces pull-request checks, update branch before requesting review. Reviewers spend less time on conflict-only diffs, and CI signals are more reliable.
This keeps integration cadence predictable.
Common Pitfalls
A common pitfall is rebasing a shared branch without informing teammates, which rewrites commits they may already use. Another issue is using plain force push after rebase, which can overwrite remote updates accidentally. Teams also often merge or rebase without fetching first, producing avoidable conflict noise. Ignoring test runs after conflict resolution is another recurring mistake. Finally, long-lived branches that rarely sync with master accumulate large integration risk and slow release work.
Summary
- Fetch first, then update branch from latest
master. - Use merge for history preservation and shared-branch safety.
- Use rebase for cleaner linear history on controlled branches.
- Resolve conflicts carefully and validate with tests before push.
- Sync feature branches frequently to reduce integration risk.

