What I would do in this case is to create a new local feature branch from the HEAD of the branch you want to contribute to (which would be in the upstream repository). Then checkout this branch and git cherry-pick
the commit range [1] that implements the feature you want to contribute (the commit range will come from your local developer branch).
After that, you can publish your new feature branch and you can submit a clean pull-request from it.