Adding steps I followed hoping that it's helpful for a beginner like me.
Following picture shows the commits I have already pushed to the remote branch 'A' in bitbucket.

From these 5 commits, I want to keep the last 2 as it is, but the first 3 commits I want them pushed to another branch 'B'.
These are the steps I followed:
Inside branch 'A':
git revert <commit-hash>
for each of the 3 commits. As an example, d4a3734 is the commit hash of the last commit in the picture. (If you want you can revert multiple commits at once - refer How to revert multiple git commits?)
git push
After the push, this is how it looked like:-

Now, I only have the first 2 commits in my branch 'A', which is what I wanted. Next, checkout to the branch wanted. If it's a new branch, use git checkout -b <branchname>
. In my case, I did git checkout B
.
Inside branch 'B':
I simply cherry-picked the commits I wanted to branch 'B'. In my case I did:
git cherry-pick <commit-hash>
for those 3 commits I reverted.
(Again, as an example, git cherry-pick d4a3734
where d4a3734 is the commit hash of the last commit in the picture)