Suppose you accidentally created branch minimum_wage_basis from bulk-approve.
Current history:
main
└── bulk-approve
└── minimum_wage_basis
Expected history:
main
└── minimum_wage_basis
Create a Backup Branch
Before rebasing, create a backup branch in case something goes wrong.
git switch feature/minimum_wage_basis
git fetch origin
git branch backup/minimum_wage_basis-before-rebase
Rebase Onto Main
Move minimum_wage_basis from bulk-approve to main.
git rebase --onto origin/main \
feature/bulk-approve-schedule \
feature/minimum_wage_basis
Verify the result:
git log --oneline --graph --decorate -10
Push Changes
Because rebase rewrites history, update the remote branch.
git push --force-with-lease origin feature/minimum_wage_basis
Restore From Backup
If the rebase result is incorrect, restore the previous state.
git switch feature/minimum_wage_basis
git reset --hard backup/minimum_wage_basis-before-rebase
After confirming everything works, remove the backup branch.
git branch -d backup/minimum_wage_basis-before-rebase