DEV Community

Discussion on: Git Rebase and the golden rule explained

Collapse
 
thebouv profile image
Anthony Bouvier

I'm going to admit something: I've never rebased.

I've never seen a reason to.

My team commits early and often, and we push to GitHub constantly. This includes our feature branches. If someone was working on a feature over two days and didn't push at the end of each day, I'd be mad. Shit happens, laptops break, and code would go away. So push your branch to GitHub.

And since it is on a remote like GitHub, and the golden rule as you say is to never rebase a branch that someone else could have pulled down, then this is always the case.

So, we never rebase. We pull master. Create a new branch. Work on it. Push it to GH. When complete, make a PR. Merge into master. Deploy. Repeat.

Collapse
 
superhawk610 profile image
Aaron Ross

I've never seen a reason to.

The biggest reason to rebase is to keep your commit history clean. If you are working on a project with many active contributors, you'll almost certainly need to merge recent changes to master into your feature branch to prevent merge conflicts. This creates a merge commit which does nothing but gum up your commit history on master when you merge it.

feat: foo
fix: bar
merge branch master into branch feature
merge branch feature into branch master

it makes grokking your commit history much easier if you rebase PRs instead of merging since it gets rid of that extra commit and makes your commit history more declarative.

Collapse
 
thebouv profile image
Anthony Bouvier

Except to do that my team has to break another rule -- don't rebase if you pushed your branch remotely because someone else could pick it up.

In fact, since making a PR requires having pushed to GitHub, shouldn't you never rebase if a PR is involved?

Thread Thread
 
superhawk610 profile image
Aaron Ross

As long as all team members are aware ahead of time, I don't think it should be a problem, just make sure to pull in the remote before doing additional work (git pull -r or similar). How often are multiple team members working on the same PR at the same time? If you ever find that's the case it signals to me that your PRs should be more focused.

Thread Thread
 
thebouv profile image
Anthony Bouvier

Rarely honestly.

Currently though the way we do things just doesn't bother me. I don't mind the extra commit of the merge and other than "slightly cleaner history", I don't see a benefit of rebase right now that would make us change.

Every time I read up on it, and I do occasionally to see if there are ways to improve our flow, after all the back and forth opinions on whether rebase is good or bad or neutral or helpful or destructive, I end up back at "Well, we're doing good now and I can't see a real good reason to do rebase yet".

Then I check again when inevitably another one of these articles comes up about it. I'm not vehemently opposed to it, I just don't get an overwhelming sense of it being "right" compared to what we do.

Thread Thread
 
superhawk610 profile image
Aaron Ross

Totally fair. At the end of the day you should favor whatever works best for your team, and I 100% agree, if it's not broken, don't try to fix it.

Collapse
 
coatsnmore profile image
Nick Coats

I have also never used rebase. You are not alone!