git bundle
is provided for this exact purpose.
Example:
-
Bundle your source repository in its entirety
git bundle create my_repo.bundle --all
-
Take “my_repo.bundle” to where your target is
-
From your target, load up your source commit objects
git bundle unbundle my_repo.bundle
…from which point you can merge/rebase/cherry-pick your desired source commits into your target repository to your heart’s content.
Otherwise, pulling works just the same:
git pull my_repo.bundle
Compared to cloning, bundles are easier to transfer because they’re smaller as your files aren’t carried in their checked out state.
Other reasons for using bundle:
-
Unlike using
clone --bare
(which doesn’t checkout your files),
bundles are created and packed as a single file so you don’t need
additional compressing/tarballing. -
You could also simply tarball your source repository (or just the
.git directory), but you’ll be carrying over all the excess cache and
garbage that builds up under .git/.