This is my first how-to ever. I'll keep it short and direct, because I hate those tutorials that keep going around the bush.
You want to transfer code from one repository to another, but you also want to keep that code's change history in the new repo.
First, let's name things properly: source repo is the repository where the code is coming from, destination repo is the one that's receiving the code.
# you should be inside the destination repo, in the desired branch
$ git remote add source-repo <REPOSITORY LOCATION HERE> # it can be either a url from Github/etc. or the path to a repository in your computer
$ git fetch source-repo # you can specify a branch if you want
$ git log source-repo/<BRANCH>
$ git cherry-pick <COMMIT HASH> # check the docs to find more ways to use this command
$ git remote remove source-repo
As you can see, it's pretty simple, although this trick uses some less known Git commants. Any questions or suggestions, send me a message!