Rebase or Merge for git?

Shawn Shaw
1 min readMar 1, 2024

--

Here is what I follow:

In general: “rebase your feature branch, then merge to main branch”. However there are two exceptions:

  1. If your feature branch has multiple developers working on it, you should opt for merge instead of rebase, as rebase rewrites commit history and is unsafe for group collaboration feature branches. Most of the time though, you will be working on some features or fixes on a feature branch alone, in that case rebasing your feature branch before merging to main branch works the best, because you are the only developer for the feature branch thus rebase fits.
  2. If you submit PR(pull request) to upstream projects, you will always be asked for a rebase instead of merge, as the main branch gatekeeper will want to keep his branch history linear.

Three extra tips:

  1. Always do git pull before git push
  2. git pull is by default using merge, because merge is just “safer”.
  3. use git push --force-with-lease instead of git push --force after rebase or amend.

--

--