I need to export a git repository content and import it in a target repository. I know of two alternatives to do it, but they do not solve my problem
a) Add the source repository as a remote and do a merge to the target. I cannot use this as both repositories are not on the same network
b) Use git archive and copy the contents to the target. In this git archive the revision info is lost.
I need something that does an archive along with the version history and enables me to merge in the target. How can this be done?
The available list of formats can be retrieved with the git archive --list command. But the Git archive command includes only the files, not the history of those files.
No it does get the full history of the remote repository.
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/.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With