github git 使用
by Felix Wu
菲利克斯·吴(Felix Wu)
Git Submodules is one of the most terrific but exhausting features in Git. I mean, we all love Git, right? But have you ever tried using Git Submodules?
Git子模块是Git中最出色的功能之一。 我的意思是,我们都喜欢 Git,对吗? 但是您是否尝试过使用Git子模块?
Actually, standalone Git Submodules aren’t hard to understand. Initializing is easily done by typing:
实际上,独立的Git子模块并不难理解。 键入以下命令即可轻松完成初始化:
git submodule add <link-to-remote-repo>
However, I recently wanted to use submodules for hosting my reveal.js presentations based on a subpath, and this got quite complicated as I didn’t had any tutorial to refer to.
但是,我最近想使用子模块来基于子路径托管我的reveal.js演示文稿,由于我没有任何教程可参考,因此这变得相当复杂。
I basically wanted to have a repository called “presentations,” so that GH-Pages would host this repository on the respective subpath (http://presentations.flxwu.com/) in which I could include my actual reveal repositories.
我基本上想拥有一个名为“ presentations”的存储库,以便GH-Pages可以将该存储库托管在各自的子路径( http://presentations.flxwu.com/ )上,其中可以包含我的实际显示存储库。
Thus, I could have separate standalone repos for my presentations which would be automatically updated in the “presentations” repository. This would cause my “firebase-101” repository to be hosted on http://flxwu.com/presentations/firebase-101.
因此,我可以为演示文稿准备单独的独立存储库,该存储库将在“演示文稿”存储库中自动更新。 这将导致我的“ firebase-101”存储库托管在http://flxwu.com/presentations/firebase-101上 。
You can also host on a custom subdomain — I have my presentations at presentations.flxwu.com/[repo name]. Therefore you can still have your other non-presentations repositories under username.github.io/[repo name]
您也可以在自定义子域上托管-我的演示文稿位于presentations.flxwu.com/[repo name]上 。 因此,您仍然可以在username.github.io/[repo name]下使用其他非演示文稿存储库。
First off, we initialize a new repository and add respective submodules to it.
首先,我们初始化一个新的存储库,并向其中添加相应的子模块。
mkdir parentrepo && cd parentrepo/git initgit submodule add https://github.com/flxwu/firebase-101
You may replace my repository link with your respective repository which you want to host on your username.github.io/parentrepo/[repository name] subpath. Just make sure that the link uses HTTPS and the repository is public.
您可以将我的存储库链接替换为您要在username.github.io/parentrepo/[repository name]子路径上托管的各个存储库。 只需确保该链接使用HTTPS并且存储库是公共的即可 。
Now commit everything and go through the usual procedure of creating the GitHub repository, adding the remote GitHub repository locally and pushing to it:
现在,提交所有内容并完成创建GitHub存储库,在本地添加远程GitHub存储库并将其推送的常规过程:
git commit -a -m "Initial Commit"git remote add origin [your github repository .git link]git push origin master
Your GitHub repository should now look like this (except with only one hooked folder in case you only added one submodule)
现在,您的GitHub存储库应如下所示(除非只有一个挂钩文件夹,以防您仅添加了一个子模块)
Now go into the settings and publish the “master” branch on GitHub Pages. You should now see this below, replacing [flxwu.com] with your own user GitHub pages domain (username.github.io if you didn’t set a custom one).
现在进入设置并在GitHub Pages上发布“ master”分支。 现在,您应该在下面看到此内容,将[flxwu.com]替换为您自己的用户GitHub页面域(如果未设置自定义域,则为username.github.io)。
You can now also set a custom subdomain:
现在,您还可以设置自定义子域:
Now, your respective submodule firebase-101
(if you didn’t add your own repo instead of mine) is hosted at subdomain.domain.com/firebase-101.
现在,您各自的子模块firebase-101
(如果您没有添加自己的仓库而不是我的仓库)托管在subdomain.domain.com/firebase-101 。
If this article helped you, follow me on twitter @flxwu
如果这篇文章对您有帮助,请在Twitter @flxwu上关注我
Delete the section referring to the submodule from the .gitmodules
file
从.gitmodules
文件中删除引用子模块的部分
Stage the changes via git add .gitmodules
通过git add .gitmodules
Delete the relevant section of the submodule from .git/config
.
从.git/config
删除子模块的相关部分。
Run git rm --cached path_to_submodule
(no trailing slash)
运行git rm --cached path_to_submodule
(不带斜杠)
Run rm -rf .git/modules/path_to_submodule
运行rm -rf .git/modules/path_to_submodule
Delete the now untracked submodule files rm -rf path_to_submodule
删除现在未跟踪的子模块文件rm -rf path_to_submodule
翻译自: https://www.freecodecamp.org/news/hosting-on-github-pages-with-git-submodules-36815856c3f1/
github git 使用