Clone a repo with submodules: override credentials

sakovias picture sakovias · May 4, 2015 · Viewed 15.9k times · Source

I have to automate cloning a repository and fetching it's all submodules. The urls for repository submodules are specified at .gitmodules. If I were to go with defaults I would just do

git clone --recursive https://username:[email protected]

The problem is credentials aren't included in .gitmodules file and I am prompted for those when I clone. I have to use HTTPS rather then SSH.

I tried to submit the credentials using git config:

git clone https://username:[email protected] my_repo
cd my_repo
git submodule init
git config submodule.my_submodule.url "https://username:password@url/my_submodule.git"
git submodule update

but I get prompted for credentials in the last update step. I've checked that the submodule url is correct and has proper credentials in .git/config file.

Answer

Sébastien Dawans picture Sébastien Dawans · May 5, 2015

After editting the .gitmodules file you need to apply changes using

git submodule sync

The next time you run git submodule update the new url will be used.