For anyone coming here to find an answer to the title, you can do git merge-base A B.
git merge-base A B
This will give you the commit where the rebase will precisely happen, so that anything above will end at the same position after doing:
git switch A git rebase B