My project is currently hosted in a private repository. I'm looking to introduce a dependency to a third party library hosted in a public repository on GitHub. How can I fork the library so that it becomes a subdirectory in my project, but I can still sync from the trunk branch of that library?
Asked
Active
Viewed 3,432 times
6
-
Do you need to modify this public project, or just incorporate it into yours and update it periodically? – Cascabel Apr 08 '12 at 20:19
-
If you need to modify this public project, you should fork instead of using it as submodule. – 3ef9g Aug 04 '16 at 07:50
2 Answers
11
This is called submodule and is described in details at http://git-scm.com/book/en/Git-Tools-Submodules
7
This sequence would get you set up:
cd <my-project-dir>
git submodule add <github repository> <my-third-party-dir> # -b <branch> optionally
git submodule init
git submodule update
At this point you've got my-third-party-dir populated with a particular commit (a detached head). Your project will have two changes.
git add .gitmodules <my-third-party-dir>
git commit -m 'Added <repository> as a submodule'

GoZoner
- 67,920
- 20
- 95
- 145