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://[email protected]/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)?
However, after cloning, you discover that the directory containing the submodule is empty. This is because Git does not recursively clone submodules by default. You can ammend this issue by adding --recursive or --recurse-submodules to your git clone command.
You can fix it by: either committing or undoing the changes/evolutions within each of your submodules, before going back to the parent repo (where the diff shouldn't report "dirty" files anymore). To undo all changes to your submodule just cd into the root directory of your submodule and do git checkout .
Simply click on the submodule > Edit and you can rename the submodule in the new window that opens up.
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, the init
step won't clone the submodule into place until you do git submodule update
, so you can do:
git config submodule.sub/foo.url https://myuser:[email protected]/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.
Actually you can specify a "relative" path to a submodule in .gitconfig
:
[submodule foo] path = sub/foo url = ./git/foo.git
This url will reference same host (https://example.com) as the repository itself.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With