FWIW, I included "scary" in my post as a tounge-in-cheek because it's something I've heard a lot from my coworkers as well. I'm glad you wrote a post I can point people to now :)
Most people just have a disgusting history which they squash into a single massive merge commit anyway.
Personally having worked in monorepo/CI/CD environments for a decade+, I couldn't go back to anything else. Shared branches with huge merges are just a worse development model overall. If you need to isolate your work, find a way to do it in mainline, you don't need a branch.
Cut a branch, commit, and then fast-forward instead of merging. If someone has updated master, rebase instead of merging master back into your branch. Forges often have an option to rebase automatically if there are no conflicts.
I work at perhaps the largest company and we don't use branches for anything but releases. It would be awkward to just start doing this on an existing git setup of course, but if your surrounding systems are built around the notion of "one version of the code" you suddenly realize the benefits.
I worked at another FAANG prior which used a web of git repos, and the ability to not merge from mainline during feature development meant that people resorted to e.g. shipping feature branches to prod on an old head, security patches were hard to integrate globally, and nobody ever knew whether a rollback was correct/safe. I'm convinced that branches just delay integration work that is on-the-whole simpler when done incrementally.
In fact large teams NEED to operate this way, you can't sensibly merge 5 different feature branches representing weeks of changes from different groups with different priorities, it's chaos.
I always rebase -i but when I tell coworkers it would be nice if they do they just say "what's the difference between that and just squashing?". I don't have a good answer. Please help.
The point of interactive rebasing is to keep several commits. Like a refactoring commit before implementing a feature. Squashing them together would not be good.
Picking one and squashing 30 are pretty different, I think.
I prefer to rebase over merge because I seem to run into fewer conflicts that way.
I prefer both over squash because inevitably I will find something that makes me go "why the fuck is that there?" And the only clue is a commit message old enough to be in kindergarten, which might have been lost in a squash.
In my experience, the person on the other end of this conversation is the one with a bunch of commits with messages like "fix", "oops", "wip", and so on.
Of course. Commits are more granular than a merge request. An MR might consist of cleanups, some refactoring for the feature, feature implementation. At least three commits. These shouldn't be a single commit, nor is the overhead of doing separate merge requests worth it.
My first SWE position worked heavily with Openstack and used the Gerrit git server, which uses a workflow convention called "PR Stacking" or "PR Chaining"Patch Sets. You'd start your feature on a fresh branch off of main, and structure your changes into individually mergable chunks (each chunk on different branches, iirc):
main <- pr-1 <- pr-2 <- pr-3
Gerrit's UI was designed around this: review the commits of each chunk, navigating between chunks, and approve individual chunks or the entire stack.
Anyways, we moved off of Openstack after some time and adopted a "squash PR merge commit" strategy per PR, but it was still encouraged to structure the individual commits in your PR like a chain of individually mergable chunks because of everyone's code review habits.
PR stacking is super common and I do it all the time. I’d never review individual commits in a PR though. That’s basically how GitHub is designed, I’m surprised at all the upvotes for reviewing commits.
Reviewing commit-by-commit can be helpful for large changes... Gives you a narrative to follow instead of sifting through the whole list of file diffs. Similar to doing a review on a set of stacked PRs. Although it's entirely up to the person submitting their code to organize it like that.
Our org was cursed with these long sprints and lazy practices often resulting in everyone trying to get reviews on huge all-in-one PRs in the few remaining days. Glad I left that!!
If you’re pushing enough code to make reviewing by commit necessary you’re probably pushing too much code at once. Not always, but in my experience almost always.
I work on a community site with a few other people and they absolutely prefer reviewing commit-by-commit (sub-change by sub-change) if it can be done that way.
Personally I've found that I also really like presenting the changes in that way -- just looking down a curated commit list with good descriptions you get an idea for what changed in a branch and what changes may need more scrutiny vs those that maybe just re-generate resources or add/update a few dependencies. Then in actual review stuff it keeps stuff that's more closely related together.
I'm confused. I make a feature branch, the plan is to squash on merge to main.
Every commit I push up is clear what changed on that commit. Many web UIs let you look at each commit diff from a pull down menu. But then when the branch is ready to merge, just squash and all of the changes are all in one.
But if someone does rebase and git push force-with-lease, then I can't tell what changes they made while reviewing their branch, if I was already tagged before the rebase.
Commit messages are exceptionally useful if you bother to write good ones. They should explain the broader "why/how" behind the change, at a level that doesn't make sense to document at any individual place in the code, while still being too narrow for a full-fledged design doc.
Discarding that context is crazy, I go back and look at this sort of thing almost every day for various reasons.
It could be, but the vast majority of people aren't willing to put the work in. It's easier to just have a stream of squashed prs, and force people to keep them relatively small and push back on large prs
This is probably just me since I'm the only one writing commits to my repo, but:
Hard disagree. I often use commit messages to briefly explain why a change was made (not just summarize what changes were made), and squashing that out of the history means losing that information if it wasn't also recorded in a comment or ticket somewhere. I use all three most of the time, but problems arise in the gap between "most" and "all" way more often than I'd like.
Eh no one cares what the git history is in feature branches or dev branches, because those are never meant to be public. It just needs to be clean when it hits mainline.
In most cases it's simpler just to do it right the first time (i.e. in the dev branch)
If you clean up your commits it is very useful. Way more useful than a stream of “this squash merge changes 1000 lines, good luck figuring out why the one line you are interested in changed”.
The ticket and PR should give a pretty good reason why something changed
If your organizational discipline is good enough that every dev has a neat trail of commits, then you should know that's an extreme outlier and your experience may not match others'.
It's much easier to look at commit history than PRs or issue numbers. Outside of a issues (which are generally unrelated to current at the moment importance), I don't have the numbers memorized
Plus you can do this from a terminal with basically nothing but git which helps a lot
In my experience, the PRs are much more second-class (outside of review comments) than the commits themselves
The git commit will still be there in 20 years time. The tickets from $ticketing_system[-3] will have changed ID number in $ticketing_system[-2] and failed to have been migrated to ticketing_system[-1] at all.
Plus, git blame is infinitely useful for working out context of what a particularly weird line of code is there screwing up your day.
My branches are a mess of merge commits. Nobody else where I work does this. One time I was going on vacation and I shared my branch with the guy who'd be taking over for me, and he basically said "I can't work with this" lol.
I almost never use it nowadays because our workflow has feature branches and mandatory squash commits for pull requests. So every feature branch eventually becomes one squashed commit and the history is kept clean. Also feature branches are usually just commits with "commit" or 1-2 words, because they're gonna be squashed anyway, and the PR title and description will end up being the commit message.
My company's Blind had a spicy thread complaining about how senior devs would prefer rebasing over merging. To me, having a commit history that tells a clear story of why the code is how it is takes precedence over preserving every little commit.
I love it how some people think their history of fixing typos, changing direction a few times, adding tests after (or before) the fact, deciding to rename things, merge in updates from main back to their WIP branch, etc. etc. all before it ever gets reviewed is some sort of dear, important data that needs to be preserved.
I want a linearized history of logical changes that I can bisect. Every commit builds and tests. That's it. Sometimes you pull things out and submit separately (or stack if you're lucky to have such a tool) if it makes sense, like refactoring something for extensibility separate from adding the new extension.
Turns out that a lot of review systems (like GitHub PRs) preserve the granular history anyway even if you squash when you merge, so it's a best-of-both worlds situation. Clean project history, but the historical PR work has all the granular commits and review history captured for anyone who ever cares to review work done in the past (no one ever does).
I love it how some people think their history of fixing typos, changing direction a few times, adding tests after (or before) the fact, deciding to rename things, merge in updates from main back to their WIP branch, etc. etc. all before it ever gets reviewed is some sort of dear, important data that needs to be preserved.
That's a different problem. You can have same useless history in rebased or in merged history. The solution is to use rebase -i BEFORE you send it to review, and then it doesnt matter, merged or rebased it will look nice
Do regular commits while you're working. Don't think too hard about it while you're in the zone.
When it's time to make a PR, sometimes it can be valuable to combine, rearrange, or split commits. But not all the time. It can depend on how your organization handles merges and who is reviewing your code.
During work: try to make smaller commits that you can later combine into better ones (combining commits is much more ergonomic than splitting them in git). It doesn't matter how exactly they look until you are done-ish. (e.g. yesterday I ended up with 50 commits in a branch and the commit messages degenerated into things like "fix", "fix2", and "another workaround because the world is a fuck". Before opening PR and tagging someone for review, I rebased it into two logically atomic changes.)
During PR review: git commit --fixup <commit sha> is your friend, you can make small commits that address individual feedback, which are easy to review. After that, git rebase -i --autosquash does the fixups for you.
It's about context. I don't need to see your intermediate work, I just need the logical building blocks. Like the famous quote, "if I had more time, I would have written a shorter letter."
Here's a thought exercise for you. If you add a line in commit A, and then remove the same line in commit B (or C, wherever), what value is it for a reviewer to see that you did that? If those commits squashed together, it would vanish like matter and antimatter (but no explosion).
So, think of the commits that you eventually push for review as logical building blocks that tell a story about what's changing and why, and not as proof of work/life or to demonstrate how much you did or did not struggle with the task.
I only split my commits up / send multiple for review on a task when there's some sort of logical before/after relationship, and there's value in doing so. Like refactoring a concrete class into an interface + multiple implementations, commit 1 might be extracting the interface, updating references everywhere to the interface, and making the main class an implementation of the interface. And then commit 2 is adding another implementation, and configuration or logic to choose which implementation to use.
If you're in some situation where you can break a change into chunks, there's value in getting that "setup" work committed to the main branch as soon as possible. Long-lived branches drift, so structural, organizational, and other changes that have no intention to change behavior and can be easily verified by the existing test suite passing, are great things to pull out and submit ahead while you work on the harder-to-review pieces of your new feature/code. This is where stacking tools are useful, because you can eagerly get those chunks stacked and submitted for review and the whole process of getting them merged in is a blip to you. It's all possible without stacking tools but you'll be learning a lot about git.
Anyway, that's all for what you present to the outside world. WHILE you work, you may want to create lots of commits. And also use the stage to your advantage. I frequently stage my work, try something, and then revert back to my staged version if it didn't work. But sometimes I just use plain old commits and branches as well. Back in the bad old days, we just had to hack on files in the local directory and, if we decided that we went down a wrong path, unless we made backups of interstitial work states ourselves, the only way to go back would be to go all the way back.
Ultimately, the confusion is that the version control system has multiple purposes. It's a history of your project, so you can reason about what code is in what version. You want linearized history for that. It's also a tool to help you find how long problems have existed in your codebase or where they began (e.g. bisecting). Linearized history is useful there as well. It serves as a tool for you to try new things and circle back to previous changes, without ever losing work. Branching paths is useful there.
I suppose a final nugget I'll leave you with, even Linus Torvalds (creator of git) has a nuanced take on merges. Which he does use! But he has said on many occasions that merges should be documented in the commit message and have an intent. Merging because it's the default option for no reason is not acceptable. You should only merge when you have a need to demonstrate that intent as part of managing your history, i.e. you want to see it when you look at your repository history.
So, linearize by default, merge* when there is a need to show intent. Rebase your local work/stream of consciousness into one or more commits depending on how & if you want to show multiple steps leading up to a final result, or multiple if there are steps worth pulling out and sharing ahead of the later steps in your own work. Use the version control tool to help you try things and track your work without losing anything, but don't make reviewers follow your stream of consciousness. Think about how you want to present your work -- not just in commits, but commit message documentation for someone reviewing the log.
* ETA - 'merge' here means git merge, not how GitHub has abused the term. A merge commit is one that joins streams of history together. GitHub calls a bunch of things "merges" that are not merges, such as a simple fast-forward.
Yep, this is the bit that made rebasing click for me: local commits can be my messy workbench, but the commits I ask others to review should be the clean story future-me can actually bisect.
I've had way more on my branch, the point is your branch is a scratchpad and you should feel empowered to change it and commit as much as you want. The pr is the presentation layer, so I typically show my viewers a single commit using rebase depending on size/complexity with a backstory or anything I learned along the way.
I think the main argument for multiple commits but a single PR is when each commit doesn’t necessarily make sense as an atomic change on main, but there’s sufficient complexity to the change to break out the commits for review. For example, I’ll often do documentation and regression/unit tests as the first commit in a PR branch, and yeah those could stand alone as a commit with all the tests disabled on main, but it’s not really useful from a history standpoint over just squashing them in with the subsequent commit that actually implements it. Sometimes it’s just a nicety for reviewers.
Recently I added metrics to our library and for reasons, we needed custom implementation of common standard. The commit for the actual implementation is atomic, and the commit for instrumenting our code is atomic, but merging the former does not make sense without the latter. Similarly, squashing them would be stupid, cause then you can't revert the instrumentation without also killing off the metric implementation, which could've gained more usage in other parts of the code in the meantime.
I’ve had to help many people after a rebase has gone wrong who thought they knew what they were doing. Rebasing should never be done IMO except for squash merges.
This is especially true for pulling things from master. You can fix a bad merge commit, but fixing a bad rebase is nearly impossible.
Yeah, this reads backwards to me. Undoing a local rebase is honestly one of the easier things in Git. It just moves HEAD, and Git logs every move, so git reset --hard ORIG_HEAD (or reflog plus a reset if you catch it later) drops you right back where you were. That's the same thing you'd do to fix a bad merge, so it's not really a point for merge.
And the whole thing was never rebase vs. anything else, it's shared vs. private branches. That's why I said my own branch. Rebasing a branch only I have doesn't hurt anyone. Every horror story you've run into is someone rewriting a shared branch and force-pushing.
Also, squash merge and rebase aren't the same thing. A squash merge smashes a branch into one commit, a rebase replays commits onto a new base. You can squash during a rebase, sure, but they're different tools.
Multiple machines aren't an issue. If you know you force pushed a branch, you can just git fetch it and then reset the local branch to match the remote one (git switch -C branch origin/branch).
If the second machine was ahead of the remote branch, git pull --rebase should do the job.
That’s the precise fucking issue. It’s very easy to get confused about what is where. You can’t really mess up a merge commit. If it goes wrong, you still have all versions leaving you the ability to revert, cherry-pick, etc. Once you rebase, you’ve committed yourself and can’t undo anything aside from praying that you can recover things from the reflog.
Now what are the advantages of rebasing again? That’s right, there aren’t really any aside from “tidiness”. I’d much rather know that any mistake I’ve made in reconciling versions is recoverable.
If I could ship a version of Git to my team which didn’t allow rebasing at all (aside from maybe amending the last commit), I’d do it in a heartbeat. It would save so me many headaches.
In my experience, the exact people who want to rebase all the time are precisely the people who shouldn’t be doing it.
If you know That’s the precise fucking issue. It’s very easy to get confused about what is where. You can’t really mess up a merge commit. If it goes wrong, you still have all versions leaving you the ability to revert, cherry-pick, etc. Once you rebase, you’ve committed yourself and can’t undo anything aside from praying that you can recover things from the reflog.
What a bunch of nonsense. If you take note of the commit hash, you can always go back, no faith required.
Not that this is a common concern. If a rebase is going wrong, you will know it's wrong before it's completed, and can just git rebase --abort. It's much easier to fuck up a merge by improperly resolving conflicts than a rebase.
Now what are the advantages of rebasing again? That’s right, there aren’t really any aside from “tidiness”.
Having atomic commits and removing garbage from the commit log. It makes PRs easier to review, and changes easier to understand.
I’d much rather know that any mistake I’ve made in reconciling versions is recoverable.
Rebases don't do away with history, unless you purposefully remove those commits. Which you'd only do if they have no value.
If I could ship a version of Git to my team which didn’t allow rebasing at all (aside from maybe amending the last commit), I’d do it in a heartbeat. It would save so me many headaches.
In my experience, the exact people who want to rebase all the time are precisely the people who shouldn’t be doing it.
People who fuck up rebases would also fuck up any other method of rewriting history. The problem isn't rebase, the problem is not understanding Git, and not understanding the transformation they want to perform.
There was a period where I viewed git as check out, do work, check in, and maybe fight with a merge conflict.
There was a real levelup shift when I started to understand how to reorder diffs, rebase on top of whatever, cherry pick specific commits, etc.
I now recommend learning git, shell commands, and the stepwise debugger as the most useful things a developer can add to their tools that isn't given nearly enough emphasis in education.
git never clicked for me. I feel more comfortable working with git after a couple of weeks with jujutsu than I did in a decade and a half just working with git.
I had multiple people at work tell me they don't want to use it because they are scared to lose some of the changes they made. I think a lot of people just find git scary in general.
Rebases can be very destructive if done wrong. They rewrite history. It was my biggest fear when I first started until a senior dev told me about rebase -i.
I use git reset --soft main then a commit and force push to clean up my feature branch commit history into a single commit. Much quicker than rebase -i.
you understand the idea of a directed acyclic graphs; and the actions one might want to do: add a node, remove a node(s), change the node (commit, reset, amend)
you understand the idea that each node in this graph (a commit) has identity that is unique and strictly dependent on its content and the parent(s) (commit hash)
you understand the premise that the tool needs to solve multiple copies of said graph (branches, both remote and local)
then you understand git.
HEAD? It's a pointer (==commit hash) to the newest commit on the current branch.
Branch? A pointer to the newest commit in the graph instance.
Tag? A label for a commit hash.
Merge? Create a commit that joins the graph that diverged at one point.
Rebase? Compare two graphs, apply the difference from your graph on top of the other graph.
Rebase -i? The same as above, but I want to have control what to do at each differing commit.
Pull? Take the remote graph and apply the differences onto mine.
Reflog? A list of pointers to nodes after each command in history. Rebase ends with a commit hash. Merge ends with a commit hash. Checkout ends with a commit hash.
Git isn't complex, it's a DAG. If you can understand data structures, then DAG's are not complex. Git commands are complex, but there is a way: it is literally easier to think what you want to do in terms of the graph and then find the command to do it.
Yet developers will fight tooth and nail to avoid spending a day of their life to understand a tool they use daily. Go figure.
I just “git merge <target> ; git reset <target” and manually pick through the version control tab in vscode. It works for me and you just have to force push and you’re good.
But if someone does rebase and git push force-with-lease, then I can't tell what changes they made while reviewing their branch, if I was already tagged before the rebase.
Doing rebase before, that's great, but doing it after, how can I be sure what's happened without reviewing everything again.
if you don't care about a clean branch history (a tiny fraction of the improvement rebasing provides) than i am more inclined to be skeptical of how serious you are about your software.
Article was fine until I got to this gatekeeping nonsense.
Whether someone prefers rebasing or merge commits is a workflow preference, not a measure of how seriously they take their software. If rebasing is objectively better, explain why. You can argue that interactive rebasing has benefits without questioning the professionalism of people who disagree.
I didn't dig into it because of the fact that this is of course, subjective, like you said. And it is not conducive to dive into that in an article like this which is just meant to explain how it works (I concede that it is very baity).
But to answer your question: IMO, if I'm reviewing a contributors PR to some project, and it's riddled with 'Merge into'/random fixup commits, or a tangled history that makes it difficult to understand the evolution of the changes, it does make me less confident that the contributor put much thought into presenting their work in a clean, reviewable way.
So building on this- would it be fair to me to then burden other maintainers/reviewers with a PR like that? Objectively speaking, it simply takes more time for a reviewer to have to sift through the commit log of a branch to understand why a PR is in the state that it is in, wherein a linear history makes it far easier for my eyes to track HEAD of master to HEAD of some PR branch.
I've reviewed it in the past, and want to see only what changed since then - having a lot of commits is annoying, and master merges straight out ruin this
It includes files with renames and content changes, hence the rename and content change operations for any file must be in 2 separate commits for the git history to be kept in master; ideally it'll only have 2 commits total to not pollute master with spam; at least this is the workflow I've made up
Why keep the source control? It's the end result that matters.
But snark aside; when commits do one thing both the history and the review is both better and faster. In theory, you are supposed to do one thing per PR. But in practice; people throw a lot of shit into the same PR, making both review harder and the history useless.
Because some commits are important, and some are not. I'm not advocating for keeping up fixups or WIP's; but to keep commits atomic. One commit should do one thing.
What happens if something breaks on master? What if it came from a PR that had n amount of messy commits, where some didn't compile, or had incomplete work? How am I supposed to bisect and find where the bug was introduced?
It sounds like you're coming from an open source perspective, since you called reviewers maintainers. I think the idea of maximizing reviewer-friendliness makes perfect sense in that context.
In most corporate environments, as a senior I'd probably get significant pushback for expecting juniors to take extra hours to make their commits readable, instead of getting actual work done -- especially since we squash commits when the PR completes anyway. If the PR is too large to easily review, then I can call them to break it down for me themselves.
I use rebase to hide my sins a lot... but I also don't commit my sins (no pun intended) as often as I see some folks doing.
There is this idea that you should use commits the same way that we used to "save files", I think committing that often is kind of a mistake (but my workflow isn't for everyone).
Anyways, I know you are joking, but I would propose that committing too often is something that many developers do and that it is much easier to learn to love rebase -i when you've only got 1 atomic commit to start with (rebasing over dozens of commits is hard work).
Yep I do use commits as "save points" but I keep it to a single commit ahead of my actual pushable atomic commit. That way I'm always rebasing HEAD~2 and just accumulating a decent commit before I push it.
Then on the last fixup I'll also reword the primary commit properly and then push.
Everything is scary until you know how to do it. Agree that rebasing requires some moderate thought if you've never considered the git tree model, but sooner or later you need to get to know your tools.
Yup, this. If you only ever use git log to look at local commits then git rebase and git reset look real spooky.
If you're long stuck in patterns that migrated from other VCS systems with different "lost my work" conditions, it'll take a minute to have a real reason to reference git reflog and realize your freedom of movement.
pretty dismissive of why this is scary though, its scary because youre destructively changing history in a way that makes rollback require a conscious strategy, not "sCaWWy BeCuZ u DoNt KnoW" but because you know it can mess things up if you use it without understanding
for comparison, it's not "scary" to use any new random feature in a modern document editor because you know that the undo function exists and works without any footguns. the fact that there's a community held notion that it's "scary" shows that the language around it's usage vs the expected effect is different enough to immediately warrant caution to others. "everything is scary until it isnt" isn't a helpful sentiment to anyone.
The issue is that the people who can fix it are not the people who break it. I'd rather endure a slightly messy timeline personally. It's a commit log not a blog post. If anything this indicates that tooling around merges could probably be improved to capture the full feature set delta more accurately, but that's not really something got can do with its current line based diffs.
I'd say you have three big friends when it comes to git rebase:
git rebase --abort.
git push and git reset --hard origin/branch (or working on a temp branch or a new worktree, it's not like they cost anything).
git diff rebased..original to catch anything you're unsure got processed right (more helpful if you're cleaning up from the same branch point than moving your branch up to a new branch point).
When I first picked up git I just read the first couple chapters of pro git and understood the design and it was pretty straight forward from there. I feel like a lot of people are just too lazy to sit down and learn something properly, but you save so much time in the long run
I feel like a lot of people are just too lazy to sit down and learn something properly
I can explain in detail both git and git internals in a 4 hour workshop for anyone that has worked with software development for more than half a year.
Given that, I refuse to believe in any other reason to avoid learning about the tool you are using daily than laziness.
You cannot tell people to "just use the reflog". If people are already struggling with interactive rebase (which is not easy to use anyway) they have never and will never use the reflog. It's way too hard to use. jj makes all of that very easy to use with an undo command (and all of the other operation log commands).
I use both. Rebase is mostly just to do cleaner commits be it long features or because git and especially tfs dont understand which files are moved/edited and which are deleted/added which will be pain for me and for reviewer.
Can someone tell me what's the problem with merge? Who's looking at git trees? In 10 years the commit count was never a problem that I cared, but I'm open to understand the appeal of using rebase instead
It keeps every commit, every typo correction and refactor made during development. If it's a year later and you're looking at file history, you don't want to have to step through every change a dev made in their feature branch. It's more useful to see the end result of what a ticket/PR changed.
Your personal or organizational git habits could make that more or less important. The "squash everything" method means it doesn't matter how much a dev twiddled the code before it got merged.
Further, merge commits can be strange to work with, especially if there's a conflict resolved.
Who's looking at git trees?
I look at git trees every day. And I don't mean the CLI output, I mean a dedicated viewer. The benefit is that I can see multiple branches at once.
In 10 years the commit count was never a problem that I cared
AFAIK, this is only useful as a quick reference for how far apart local is from origin.
I'm open to understand the appeal of using rebase instead
People talk about "merge vs rebase", but they're really different tools. Rebase can accomplish similar things to merge, but it can also do a lot more.
Rebase is ultimately for manipulating the commits in a branch. If you ever need to combine, split, or rearrange commits in a branch, rebase is the tool.
It's more about the convention your team agrees to and what you find easier to reason about.
Mine squashes commits to merge PR's as a single commit. I like rebasing to the head of the main branch because, even if Git is perfectly fine with complex commit graphs, I have an easier time reasoning about changes as atomic points in the timeline. I like to rebase to reconcile the changes because I'm basically re-applying each commit incrementally.
Plenty of others don't use it, but I prefer it to merging in that particular case.
I don't get this -- a merge commit is still a commit, and contains all the changes from the branch + anything required to make it work with main. It can be reverted just the same as any other.
Rebase is still definitely a useful tool (it means the merge commit is going to contain only the changes from the branch, not the merge-fix stuff), but rebase/squash/fast-forward introduces problems of its own that rebase/merge-no-ff doesn't have (chiefly losing the "why" for each clean change from commit messages and allowing later rebased branches to neatly drop cherry-picked commits).
People want a "clean history" with varying levels of violation of versioning.
It's the retroactive changes discussion all over again, some people want their way of working to affect the past, other people firmly disagree about new changes affecting the past, especially in a versionning system that keeps track of changes.
The rule is generally simple, you rebase locally before pushing to repo (eg: WIP, typo, fix tests etc...), people don't want to see your 50 commits of WIP but you can squash all of them into the actual thing they did in one nice commit that reaches the CI repo.
Devops and devs want clean commits on branches. Devops generally don't allow any changes once a commit reached CI, some allow to alter history on branches but most devops won't allow you to change master's history.
Many devs want clean master history where they constantly alter the past to ensure everything is tidy according to their tastes, most devops won't allow them, they get salty and complain that in one company they worked for they did just that and it was amazing.
Merge can’t clean up your history ready for review. Rebase lets you squash fixups into the proper commit, re-order or split commits if it makes more sense from a review perspective, and pull out into a separate branch if some aspects of the change get too big for one PR.
Merge puts work that is not yours into your branch. This is greater chance for conflict if you're stacking branches or upstream changes things you've merged i.e. cognitive load and degree of difficulty go up should conflicts arise. Better to rebase often, keep churn out of your commits, and keep your branch to just the amount of change you want to manage.
It’s not scary. It is annoying as fuck. Complicated rebases always require aborting and retrying way too often, and need to be done both linearly and to completion.
Since moving to jj, they have become a complete non-issue.
The thing that makes it scary for folks that I’ve seen is the first rebase goes fine. But they forget to push —force-with-lease and let their colleagues know. Compound that with merging the main baseline in to the feature branch and rebasing again, and now PRs have other people’s commits. Also they forget that it replays each commit again, so they have to keep doing what feels like the same merge resolution over and over again. Sometimes I’ve seen an attempted pull during a rebase. So in short, folks that don’t understand git and are just replaying magic incantations hoping something works end up shooting themselves in the foot. The sad thing is any LLM will not only tell you what to do, but why, so the self inflicted pain is avoidable and any trouble that’s gotten into can be recovered from. Once we educated folks properly, rebase is the tool they reach for most often because it reduces merge collisions.
It is not scary, but rather amazing. You can simply fixup necessary updates in commits and overall keep clean and readable history.
The problem I know (that is ugly rather than scary) - if you use that with shithub (Github) and want someone to review changes and track those (force-update Gerrit approach). That becomes pain, but rebase is still amazing and powerfull.
One thing that makes it reall unintuitive: git rebase -i gives you the commits in the opposite order compared to git log. It really trips up people the first time they use it.
Rebase is a god send once you’ve learned it. I’m still told over and over again by people I consider to be brilliant engineers that its useless bloat that will just fuck up my history irreparably, and I just don’t understand why people refuse to see the obvious use case.
I think making a tag is better backup advice than making a branch though it probably adds some more text because git novices are less likely to know about tags.
Maybe I'm the problem here. I'll explain my aversion for others to criticise of they wish.
I'm a senior solutions architect and have been an engineer before that for around 10 years. I've never done a rebate, ever.
Everything I've ever needed to do, ever I've done with git merge, reset --hard or git amend. I exclusively use the CLI. For conflicts I always use my IDE to show me the diffs and I'll resolve them in there.
Obviously there's an element of taste/personal preference as well as things being objectively better/worse. For those who rebase, what am I missing out on? I personally don't have any fear of doing it, just got into the habits of my ways I guess.
What if you have multiple commits on your active branch, and you need to change the one that is not the latest?
Or if you need to resolve a conflict with a main branch before a merge, do you need to keep the merge commit in the history of your branch?
First one is rebase -i with commit --fixup; second one is a bit subjective.
I tend to have multiple commits active. Since I work in a strictly atomic way; I might have:
Reformat code in file X
Boy scout cleanup in file X
JIRA: Create generic mechanism in file X
JIRA: Implement another implementation in the X
And I am talking about short lived branch, not a multi-day feature branch. At any given point I might find e.g. a small thing that is not related to my ticket, but to a cleanup - so I quickly do a partial commit in the form of --fixup and I'll rebase it later. I might decide that before I merge things to main I want to split it - rebase again.
If I diverge from the main to the point of conflict; both reformat and cleanup do not need to exist on a separate branch, they can be rebased and linearly pushed with --ff. For the feature itself, I might want to keep them as a branch (because in the future, branch gives context) and do a merge commit.
So for me branch (and merge) serves a role of grouping the changes. If branch does not give me any value, rebase and merge --ff. If it does, merge --no-ff.
Hell, at one point I've decided to do some spicy stuff and did octopus merge; with 4 parent commits. Good times; legitimate use-case, I expect only a handful over my whole career.
Had a senior architect tell me that rebasing is dangerous for version history and from now on he wants me to merge into the feature branch to then merge back into prod.
To that I'll say: As long as it is your branch, and it is unmerged - do what the hell you want. Rebase is not dangerous at all, you have reflog; and merges into the feature branch (especially with short lived branches) serve little to no purpose.
I have looked for a good reason to use git rebase and still have not found one. If you want to merge conflicts from commits that arent relevant anymore, rebase is definitely the way to do it.
You don’t rebase on main, you rebase against main on local feature branches. You won’t generate any conflicts that way because you aren’t rewriting any pushed hashes. It’s just a valuable tool to make your working branches clean.
This is my understanding, and I must be missing something because everyone recommends rebase.
All rebase does is move the commit my branch was created from. So, instead of merging all the commits to master from when I branched off, I instead essentially "recreate" the branch at HEAD on master and reapply all the commits on my branch to that. I commit to feature branches frequently, at LEAST once a day at the end of the day. Sometimes, the changes I make in those commits are overwritten by later commits in the same branch. Rebase forces me to reapply those intermediate commits onto master, even if a later commit will overwrite whatever I did. If the files changed on master as well, those commits will have conflicts I will have to resolve.
Resolving merge conflicts is probably one of the most "dangerous" things I do as a software guy. It's taking someone else's changes, of which I may or may not have the full information on, and merging them into my own branch. Why would I want to force myself to do that? How does it make my branch cleaner?
Rebase has two main uses. You mentioned the first.
The second use is when you're not merging any changes, that's the -i flag. In that mode, you edit commits of the branch you are on right now. I.e. you can change the commit messages, squash some commits together, reorder them, etc.
I meant if your branches only live for a few hours, you aren't doing very big features (projects), and it makes sense that you wouldn't care, there's not much to care about.
It's when there's a feature branch that gets unwieldy where the benefit comes in.
578
u/MafiaMan456 Jul 14 '26
Do people find it scary? It’s been part of my workflow for cleaning up my commit history on feature branches for over a decade…
4
u/TheSameTrain Jul 15 '26
Capital letters are also not that scary
14
u/wildjokers Jul 14 '26
Article was fine until I got to this gatekeeping nonsense.
Whether someone prefers rebasing or merge commits is a workflow preference, not a measure of how seriously they take their software. If rebasing is objectively better, explain why. You can argue that interactive rebasing has benefits without questioning the professionalism of people who disagree.
31
u/longshot Jul 15 '26
Jeez, I use rebase -i to hide my sins about 30 times a day
93
u/robe_and_wizard_hat Jul 14 '26
Everything is scary until you know how to do it. Agree that rebasing requires some moderate thought if you've never considered the git tree model, but sooner or later you need to get to know your tools.
23
u/TheChildOfSkyrim Jul 14 '26
I use if for everything, even for cherry-picks: you can add arbitrary commit ids at any point in the TODO list, and git will make it happen.
18
u/randfur Jul 15 '26
Use jj (compatible with git!) then nothing is scary because you can just undo (yes, that means the version control is version controlled).
16
u/wannaliveonmars Jul 14 '26
Yes, I liked using it a lot back in the day, mostly for fixups, occasionally to reorder commits and so on.
57
u/sweetno Jul 14 '26 edited Jul 14 '26
Yes, it's not scary, the scary part is exiting the editor.
P.S. Check out lazygit.
21
u/Thornado1647 Jul 14 '26
Was it scary at some point?
6
u/eocron06 Jul 14 '26
I use both. Rebase is mostly just to do cleaner commits be it long features or because git and especially tfs dont understand which files are moved/edited and which are deleted/added which will be pain for me and for reviewer.
20
u/tgo1014 Jul 14 '26
Can someone tell me what's the problem with merge? Who's looking at git trees? In 10 years the commit count was never a problem that I cared, but I'm open to understand the appeal of using rebase instead
9
u/stouset Jul 15 '26
It’s not scary. It is annoying as fuck. Complicated rebases always require aborting and retrying way too often, and need to be done both linearly and to completion.
Since moving to jj, they have become a complete non-issue.
4
u/wls Jul 15 '26
The thing that makes it scary for folks that I’ve seen is the first rebase goes fine. But they forget to push —force-with-lease and let their colleagues know. Compound that with merging the main baseline in to the feature branch and rebasing again, and now PRs have other people’s commits. Also they forget that it replays each commit again, so they have to keep doing what feels like the same merge resolution over and over again. Sometimes I’ve seen an attempted pull during a rebase. So in short, folks that don’t understand git and are just replaying magic incantations hoping something works end up shooting themselves in the foot. The sad thing is any LLM will not only tell you what to do, but why, so the self inflicted pain is avoidable and any trouble that’s gotten into can be recovered from. Once we educated folks properly, rebase is the tool they reach for most often because it reduces merge collisions.
4
u/BusEquivalent9605 Jul 15 '26
f rebase. we merge over here
5
u/ImpactfulBird Jul 14 '26
It is not scary, but rather amazing. You can simply fixup necessary updates in commits and overall keep clean and readable history.
The problem I know (that is ugly rather than scary) - if you use that with shithub (Github) and want someone to review changes and track those (force-update Gerrit approach). That becomes pain, but
rebaseis still amazing and powerfull.2
u/Waltr-Turgidor Jul 14 '26
I used it all the time in the past
2
u/Skaarj Jul 15 '26
One thing that makes it reall unintuitive:
git rebase -igives you the commits in the opposite order compared togit log. It really trips up people the first time they use it.2
u/Multidream Jul 15 '26
Rebase is a god send once you’ve learned it. I’m still told over and over again by people I consider to be brilliant engineers that its useless bloat that will just fuck up my history irreparably, and I just don’t understand why people refuse to see the obvious use case.
2
u/StruggleNew8988 Jul 15 '26
Rebase is great for keeping your feature branch clean before you push it up for review, that's the main win I see from it.
1
u/iamaperson3133 Jul 15 '26
I think making a tag is better backup advice than making a branch though it probably adds some more text because git novices are less likely to know about tags.
1
u/Wise_Royal9545 Jul 15 '26
claude -p “rebase this branch on main”
1
u/Dragdu Jul 15 '26
Capital letters motherfucker, have you heard of them?
1
u/kris_lace Jul 15 '26
Maybe I'm the problem here. I'll explain my aversion for others to criticise of they wish.
I'm a senior solutions architect and have been an engineer before that for around 10 years. I've never done a rebate, ever.
Everything I've ever needed to do, ever I've done with git merge, reset --hard or git amend. I exclusively use the CLI. For conflicts I always use my IDE to show me the diffs and I'll resolve them in there.
Obviously there's an element of taste/personal preference as well as things being objectively better/worse. For those who rebase, what am I missing out on? I personally don't have any fear of doing it, just got into the habits of my ways I guess.
1
u/Anomynous__ Jul 15 '26
Had a senior architect tell me that rebasing is dangerous for version history and from now on he wants me to merge into the feature branch to then merge back into prod.
0
u/az987654 Jul 18 '26
I've never been afraid of any command because I read the documentation
-10
u/Pinilla Jul 14 '26
I have looked for a good reason to use git rebase and still have not found one. If you want to merge conflicts from commits that arent relevant anymore, rebase is definitely the way to do it.