Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save thecodermehedi/0901c03d0c1d812b375677a545b79747 to your computer and use it in GitHub Desktop.
Save thecodermehedi/0901c03d0c1d812b375677a545b79747 to your computer and use it in GitHub Desktop.
If you want zero merge commits and a perfectly linear history, here's your git workflow scenario ( example , main is release branch, and dev is developerment)

1. Make Sure Everything Is Up to Date

git switch dev
git pull origin dev
git switch main
git pull origin main

2. Rebase dev onto 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

3. Fast-forward main to dev

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.

4. Push main to remote

git push origin main

Why does this work?

  • 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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment