Let's call your gits A and B and say you're working on the master branch. While in git A, add B as a remote and fetch its contents into A:
git remote add B /path/to/B
git fetch B
(You don't have to add it as a remote; you can just do git fetch /path/to/B master:B/master
if you like. This copies all branches in B which might be unnecessary in your case. Feel free to specify an explicit refspec to limit the fetch.)
Now you can use git-cherrypick
to copy individual commits from B to A, or use git rebase --onto
to copy multiple commits. The latter command has this general form:
git rebase --onto destination boundary starting_point
Git walks backwards from starting_point
until it reaches boundary
and copies the resulting commits (excluding boundary
) onto the tip of destination
. Thus, this copies the three most recent commits from B's master branch to A's master branch:
git rebase --onto master B/master~3 B/master