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 as myuser (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
.gitmodulesthat looks like:… i.e. without a user name, and then tell each developer to put their username and password in their
~/.netrcfile. (If you’re using Windows, then there is some good advice on that here.) A simple.netrcfile might look like:Update: An alternative, which doesn’t involve using
.netrc, would be the following:Again, remove the user name from the URL in
.gitmodulesand commit and push that change. When someone clones the repository they would first run:… which will set the config option
submodule.sub/foo.urlto the URL in.gitmodules. However, theinitstep won’t clone the submodule into place until you dogit submodule update, so you can do:… and then:
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.