Import repository with git subtree


git subtree can be used to import a Git repository into another repository.

git subtree add

Import a Git repository into another repository with add:

$ git subtree add --prefix <prefix> <repository> <revision>

add example

To import the repository [email protected]:remarkablemark/example.git into the current repository’s subdirectory ./example/:

$ git subtree add -P example [email protected]:remarkablemark/example.git master

You can check the commit output with git show:

$ git show
Add 'examaple/' from commit 'e28d0c5ef4c8e69eacea877af979923926f0c5e9'

git-subtree-dir: example
git-subtree-mainline: 32120bbb677c6786d7219de6c8c83b4bb8fc9ba0
git-subtree-split: e28d0c5ef4c8e69eacea877af979923926f0c5e9

git subtree pull

Update to the latest revision on the subtree repository with pull:

$ git subtree pull --prefix <prefix> <repository> <revision>

pull example

Continuing with our earlier example, we can do the following to fetch and merge the latest from our subtree:

$ git subtree pull -P example [email protected]:remarkablemark/example.git master


If you enjoyed this post, please consider supporting this site!