Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/mercurial/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
GitHub:如何将公共存储库作为私有存储库中的子目录分叉?_Git_Github - Fatal编程技术网

GitHub:如何将公共存储库作为私有存储库中的子目录分叉?

GitHub:如何将公共存储库作为私有存储库中的子目录分叉?,git,github,Git,Github,我的项目当前托管在私有存储库中。我希望在GitHub的公共存储库中引入对第三方库的依赖。如何分叉库,使其成为我项目中的子目录,但我仍然可以从该库的主干分支进行同步?这称为子模块,详细描述见此序列将帮助您设置: cd <my-project-dir> git submodule add <github repository> <my-third-party-dir> # -b <branch> optionally git submodule i

我的项目当前托管在私有存储库中。我希望在GitHub的公共存储库中引入对第三方库的依赖。如何分叉库,使其成为我项目中的子目录,但我仍然可以从该库的主干分支进行同步?

这称为子模块,详细描述见

此序列将帮助您设置:

cd <my-project-dir>
git submodule add <github repository> <my-third-party-dir>   # -b <branch> optionally
git submodule init
git submodule update
cd
git子模块添加#-b(可选)
初始化子模块
git子模块更新
此时,我的第三方目录已填充了一个特定的提交(分离的头)。您的项目将有两个更改

git add .gitmodules <my-third-party-dir>
git commit -m 'Added <repository> as a submodule'
git add.gitmodules
git提交-m'作为子模块添加'

您需要修改此公共项目,还是将其合并到您的项目中并定期更新?如果需要修改此公共项目,您应该使用fork,而不是将其用作子模块。