Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GitHub: How to fork a public repository as a subdirectory in a private repository?

Tags:

git

github

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?

like image 572
zer0stimulus Avatar asked Apr 08 '12 18:04

zer0stimulus


People also ask

Can I fork a public repo to private GitHub?

Github does not allow a forked repository to be private. This article describes a way to make a private repo that can pull new features of a public repo. The private repo will behave just as a forked repo of the public repo.

Can I fork into an existing repository?

You can fork any repo by clicking the fork button in the upper right hand corner of a repo page. Click on the Fork button to fork any repo on github.com. Source: GitHub Guides.


2 Answers

This is called submodule and is described in details at http://git-scm.com/book/en/Git-Tools-Submodules

like image 166
xeor Avatar answered Oct 27 '22 11:10

xeor


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'
like image 26
GoZoner Avatar answered Oct 27 '22 10:10

GoZoner