Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git submodule update with other user

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?

like image 564
Jonas Byström Avatar asked May 18 '11 07:05

Jonas Byström


People also ask

How do I sync submodule?

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.

How do I update my submodule remote?

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.

Can you make changes to a git submodule?

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).


1 Answers

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.

like image 55
Mark Longair Avatar answered Sep 21 '22 05:09

Mark Longair