Git子模块URL不包括用户名? [英] Git submodule URL not including username?
问题描述
我有一个设置了几个子模块的git仓库,它创建一个 .gitmodules
文件,它是父库中的一个跟踪文件。但是,还有其他开发人员希望在此存储库上工作,并查看子模块。但是,目前远程子模块存储库的URL包含我的用户名;在 .gitmodules
文件中,它就像这样:
[submodule foo]
path = sub / foo
url = https://myuser@example.com/git/foo.git
很明显,其他开发人员无法从 example.com
中以 myuser
没有我的密码);我怎么能有一个主要的存储库,多个开发人员可以拉/推,并允许他们单独访问子模块(设置一个用户名,他们都在子模块主机服务器上共享,但不是好的用户管理)如果我理解正确,那么您通过HTTPS使用HTTP基本身份验证来仅允许特定开发人员访问存储库。在这种情况下,您可以提交 .gitmodules
,如下所示:
[submodule foo]
path = sub / foo
url = https://example.com/git/foo.git
......即没有用户名,然后告诉每个开发者将他们的用户名和密码放在他们的〜/ .netrc
文件。 (如果您使用的是Windows,那么有一些很好的建议) .netrc
文件可能如下所示:
登录myusername
密码areamandyingtotellsomeonehiscoolpassword
更新:另一个不涉及使用 .netrc
的替代方法如下: 再次,从 .gitmodules
中的URL中删除用户名并提交并推送该更改。
当有人克隆版本库时,他们首先运行:
git submodule init
pre>
...这会将配置选项
submodule.sub / foo.url
设置为.gitmodules
。但是,在执行git子模块更新
之前,init
步骤不会克隆子模块,因此您可以执行:
git config submodule.sub / foo.url https:// myuser:mypass@example.com/git/foo。 git
...然后:
git子模块更新
使用正确的用户克隆子模块名称。请注意,您的用于HTTP身份验证的用户名和密码将存储在您的git config中。
I have a git repository set up with several submodules, which creates a
.gitmodules
file that is a tracked file in the parent repository. However, there are other developers wanting to work on this repository, and check out the submodules. But currently the URLs for the remote submodule repositories contain my username; in the.gitmodules
file it's something like:[submodule foo] path = sub/foo url = https://myuser@example.com/git/foo.git
Obviously other developers can't fetch from
example.com
asmyuser
(they don't have my password); how can I have one main repository that multiple developers can pull/push to, and allow them to have individual access to the submodules (setting up a single username they all share on the submodule host server would work, but is not good user management)?解决方案If I understand correctly, you're using HTTP basic authentication over HTTPS to allow only particular developers to access the repository. In that case, you can commit a
.gitmodules
that looks like:[submodule foo] path = sub/foo url = https://example.com/git/foo.git
... i.e. without a user name, and then tell each developer to put their username and password in their
~/.netrc
file. (If you're using Windows, then there is some good advice on that here.) A simple.netrc
file might look like:machine example.com login myusername password areamandyingtotellsomeonehiscoolpassword
Update: An alternative, which doesn't involve using
.netrc
, would be the following:Again, remove the user name from the URL in
.gitmodules
and commit and push that change. When someone clones the repository they would first run:git submodule init
... which will set the config option
submodule.sub/foo.url
to the URL in.gitmodules
. However, theinit
step won't clone the submodule into place until you dogit submodule update
, so you can do:git config submodule.sub/foo.url https://myuser:mypass@example.com/git/foo.git
... and then:
git submodule update
To clone the submodules with the right user name. Note that then your username and password for HTTP authentication will be stored in your git config.
这篇关于Git子模块URL不包括用户名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!