TIL - Rebasing a branch onto a different base

Search for a command to run...

No comments yet. Be the first to comment.
The Problem Today, I learned that concatLatestFrom in NgRx does not wait for an observable to emit a valid value before proceeding. Instead, it simply grabs the latest available value at the time an action is dispatched. If the observable has not emi...

What is the tap operator? I recently learned about the tap operator when trying to perform a side-effect inside of a map operator. While you could perform side-effects inside of a map operator, it's a better practice to do so in a tap operator where...

As someone new to RxJS, I found the Operator Decision Tree page incredibly helpful. This page provides a visual guide that simplifies the process of choosing the right RxJS operator by presenting a series of questions that lead you to the optimal cho...

An API Client Alternative

Today I learned how to move a branch that was incorrectly based on another branch to a different starting point. This was useful when I wanted to merge a feature branch sooner but realized it was branched off the wrong base.
Branch A is the main branch.
Branch B was created from A and has some changes.
Branch C was created from B but makes completely different changes than B.
I needed Branch C to be based directly on Branch A so I could merge it sooner without waiting for B.
To move Branch C’s changes onto A, I used the following rebase command:
git checkout c
git rebase --onto a b c
git checkout c → Switch to Branch C.
git rebase --onto a b c → Rebase branch C from being based on B to instead be based on A.
--onto a → Moves branch C to start from branch A.
b c → Tells Git that branch C was originally based on B and should be moved.
If there were conflicts, I resolved them manually and continued the rebase with:
git rebase --continue
If needed, I could abort the rebase with:
git rebase --abort
Since this rewrites history, if Branch C was already pushed, I had to force push:
git push --force
Use git rebase --onto <new-base> <old-base> <branch> to move a branch to a new base.
Always check for conflicts and resolve them carefully.
Force-pushing (--force) is needed if the branch was previously pushed, but use it cautiously.
This trick helped me clean up my Git history and merge my feature branch faster!