Let’s say you have to two git branches. You want to rebase with master to get the new changes, but you only want to keep the commits M and N.
A-B-C-D-E-F-G master
\-K-L-M-N feature1
You could achieve this by resetting feature1 to master and cherry-picking M and N.
Another way to solve this would be by using git rebase --onto.
$ git rebase --onto master HEAD~2 feature1
Now the branches will look like this.
A-B-C-D-E-F-G master
\-M-N feature1