19

I've been learning Git recently and came to know rebasing is good in some cases to avoid merge commits and keep history clean.

Also I read that extra care should be taken while using git rebase.

Can someone please describe some cases in answers below, in which cases using git rebase is a bad choice.

nwinkler
  • 52,665
  • 21
  • 154
  • 168
Foolish
  • 3,952
  • 33
  • 46

1 Answers1

9

Case 1: We should not do Rebase on branch that is public, i.e. if you are not alone working on that branch and branch exists locally as well as remotely rebasing is not a good choice on such branches and it can cause commits with same changes but different SHA ids.

Case 2: We should not do Rebase on pushed commits, i.e. If you are working on branch br1 and you already have pushed some commits to this branch on remote (or origin) you should not do rebase on this branch br1. Check this Question for reference: Rebasing and what does one mean by rebasing pushed commits

Foolish
  • 3,952
  • 33
  • 46
  • 1
    Case 1 is a valid point and agreeable but case 2 is at some scenarios to have a clean commit history you'd want to rewrite the history unless the branch is not diverged at any point. So my point here is , one can still rebase the tip and use --force-with-lease option while pushing which cautiously rewrites the remote history – Vijaykrish93 Jul 09 '19 at 16:45
  • 1
    What is a bubble commit? – rakesh mehra Jun 24 '22 at 06:13
  • 1
    @rakeshmehra same changes with two different commit SHA ids. (sorry for confusion it is in house term we used during git training) – Foolish Jun 27 '22 at 05:59