What I wish I new about `git rebase --onto`
How naive I was before I saw the light

Working in a shared git repository, though much nicer (and safer) than trying to manage a large team directly changing files on an ftp server, still has its challenges.
How many times have you been waiting for a PR to merge and created your own stacks of PRs on top of PRs only to have one of those "base" PRs land with a squash merge and send you on an uncomfortable trip down rebase lane? For me, too many times.
What if you could just apply your changes onto the squashed commit without having to handle merge conflicts between the base branch and itself? It turns out, you can with git rebase --onto
.
simply find the 2 commit SHAs base-sha
from the initial base branch and merge-sha
from the new base branch and run git rebase --onto merge-sha base-sha
I hope this helps someone else as much as it helped me 😄
Tzvi Melamed
Software Engineer & Writer
Sharing insights and experiences from the world of software development.
Learn more about me →Yoo-hoo
I'm always looking for interesting stories, different perspectives, and opportunities to learn from fellow developers. If you like what you read, reach out!
Contact me →Enjoyed this article?
Follow me on social media for more insights like this. Newsletter coming soon!