I'm logged in as user A on my machine, but my repo is accessible through username B on the server that I pull from. The .gitmodules
file has url = ssh://domain.com/abc/def.git
.
How can I configure git to use a username B instead of A when I do git submodule update
?
You need to run git submodule sync to apply the remote repo's configuration to your local submodule repos. Note also that, if you are making changes to the submodules, you might want the URLs to mismatch even if the upstream never changed them ... but using multiple remote URLs is probably a better idea for that case.
In order to update an existing Git submodule, you need to execute the “git submodule update” with the “–remote” and the “–merge” option. Using the “–remote” command, you will be able to update your existing Git submodules without having to run “git pull” commands in each submodule of your project.
Pushing updates in the submodule. The submodule is just a separate repository. If you want to make changes to it, you should make the changes in its repository and push them like in a regular Git repository (just execute the git commands in the submodule's directory).
I assume that the submodule has already been initialized, so git config --list | grep ^submodule
shows something like submodule.my-submodule.url=ssh://domain.com/abc/def.git
.
If you haven't yet run git submodule update
for the first time, then you can just change that config option, e.g. with:
git config submodule.my-submodule.url ssh://[email protected]/abc/def.git
On the other hand, if the submodule has already been updated once, then origin
in the submodule will have been set to whatever that config option specified. In that case, you'll need to do:
cd my-submodule git config remote.origin.url ssh://[email protected]/abc/def.git
It's just a bit confusing, I'm afraid, but submodules are very flexible. I made an attempt to explain some of these details in a blog post.
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