Hacker News new | ask | show | jobs
by RandallBrown 1045 days ago
I use rebase multiple times per day. Mostly for putting my changes on top of the latest development branch, but also for squashing commits.

I'm curious why you don't like it?

2 comments

My branches are always focused on a single atomic change†, so if I want the tip of my branch to be up-to-date with main (or the dev branch or whatever), merging from that branch accomplishes the same thing with a lower likelihood of conflicts.

I always squash‡ before pushing a PR, so the end result is identical to a carefully rebased PR.

† occasionally branches will need to be split into separate commits, but that's not my default working style

‡ I know `squash` is a rebase under the hood, but it won't ever result in conflicts, so I'm happy to use it with every PR

I think you'd get a lot less pushback if you mentioned that you squash every branch before merging in your original comment. That actually seems like a pretty good policy if you can keep your branches relatively small.
How/why do you use rebase for squashing?
Rebase is pretty much just an automation for cherry-picking and squashing, and interactive rebase is the primary and most convenient way to put the branch you have worked on into shape before presenting it to someone else.

When I hear about people not using rebase in their daily workflow, I imagine myself 10 years ago when I barely knew git and couldn't really use it as a helpful tool like I do today. It's almost like looking back to before I started using VCS in the first place - somehow I did manage to not use one for years (even collaborated via FTP!), but now it seems impossible. Usually most of the useful magic with git happens before anything gets pushed out, and `git rebase` has a huge part in it.

Use the interactive rebase. It shows a list of commits which you can reorder, squash, remove or edit.

Reordering is pretty powerful. If you made a mistake, commit the fix, then move it to the commit where you introduced the mistake, and squash. Removing broken commits makes `bisect` nicer to use when you're desperate enough to use it.

Obviously don't do this on commits you've already published.