git switch dev
git pull origin dev
git switch main
git pull origin main
This puts all your dev commits “on top of” main, making the history linear and avoiding merge commits.
git switch dev
git rebase main
Now, switch to main and make it match dev exactly (no merge commit, just moves the pointer forward):
git switch main
git merge --ff-only dev
--ff-only
ensures Git will only fast-forward (no merge commit). If for some reason main can’t be fast-forwarded, this will fail and warn you, preventing unwanted merge commits.
git push origin main
- Rebasing makes dev’s history linear on top of main.
- Fast-forward merge moves main to dev without a merge commit.
- No extra commits, no clutter, just a straight, readable history.
This is the gold-standard workflow for teams or individuals who want a clean, “merge-commit-free” history!