How can I add a subdirectory of another git repository?

Viewed 486

I'd like to add a subfolder of a public github repository into a subfolder of my own repository. I found a few solutions with git-sub-tree but there seems to be no way to pull changes from the original repository.

Is there a solution where I can merge changes from upstream?

2 Answers

Did you try submodules? I think they will work for your use case.

If you need just one folder, you could clone the repo in another directory and then symlink the needed subdir.

$ pwd
> my-repo
$ cd ..
$ git clone <other-repo>
$ cd my-repo
$ ln -s ../other-repo/path/to/subdir ./directory/for/subdir/from/other/repo
Related