Answering your main question: If you want to do this using patches, on repo A:
git format-patch <starting hash>..<ending hash>
Then, on repo B:
git apply <each patch file generated using the above method>
I'd caution you to make sure the files are very similar, though. Patches can be a pain to apply correctly if the repositories have diverged much.
Second approach: Depending on how similar the repositories are, it may be useful for you to add repo A as a secondary remote for repo B. This would allow you to fetch and cherry-pick commits as you do with any other upstream repository and avoid patch files altogether.
This would look like:
git remote add repoA <path to repo A>
git fetch repoA
git cherry-pick <relevant commits in repo A>
This:
- Adds Repo A as a second remote.
- Fetches Repo A's commit history.
- Cherry-picks the relevant commits to your current repository.
That said, there is a lot of unnecessary overhead in adding a second remote, such as downloading a lot of unnecessary history, so you may find that patches suit your problem better.