Stop Rebasing Every Time: A Safer Way to Keep Your Git Branch Updated with `master`
If you work on long-lived feature branches, you've probably experienced this: master (or main ) keeps moving. Your branch falls behind. Pull requests become harder to review. Merge conflicts get bigger every day. Many teams solve this by rebasing their feature branches. Others—including many enterprise teams—prefer merging the latest master into the feature branch to preserve commit history and avoid rewriting commits that may already be shared. If your workflow uses merge instead of rebase, this article shows how to make the process much faster with a custom Git alias. The Problem Imagine your repository looks like this. master A──B──C──D feature/login \ E──F While you're developing, your teammates merge several pull requests. master A──B──C──D──G──H──I feature/login \ E──F Now your feature branch is missing the latest changes. If you don't sync it: merge conflicts accumulate CI may fail unexpectedly testing becomes less reliable your eventual pull request becomes much harder to review Keeping your branch up-to-date regularly makes integration much smoother. Updating Your Branch Manually Suppose you're working on: feature/login and want to sync it with master . First, fetch the latest changes: git fetch origin Switch to your feature branch: git checkout feature/login Reset your local branch to match the remote version: git reset --hard origin/feature/login Why reset? This ensures your local branch exactly matches the remote branch before merging. It's useful if your local branch is only a working copy of the remote branch. Warning: Any unpushed commits will be permanently deleted. Merge the latest master : git merge --no-ff origin/master Finally, push the updated branch: git push Your history now becomes: master A──B──C──D──G──H──I \ feature/login M \ / E──────F where M is the merge commit. That's a Lot of Typing... Every time you want to synchronize a branch, you're repeating the same commands: git fetch git checkout feature/login git reset --hard origin/feature/l