tags:

views:

753

answers:

3

I've created a git repository with a submodule in it. I'm able to tell the submodule itself to change its remote repository path, but I'm not sure how to tell the parent repository how to change the remote repository path for the submodule.

I wouldn't be surprised if I'm somewhat out of luck and have to do things manually, as even deleting submodules isn't easy.

Edit: I ended up getting rid of submodules and just had a working copy within another working copy, so I'm asking out of curiosity now.

The instructions given below seem to work in some circumstances, but apparently not in others.

+4  A: 

You should just be able to edit the .gitmodules file to update the URL and then run git submodule sync to reflect that change to the superproject and your working copy.

Jim Puls
I agree. +1 (see my answer for additional details)
VonC
What affect should git submodule sync have? Am I doing it incorrectly in http://gist.github.com/120723 , or am I incorrect in expecting .git/config to be changed by git submodule sync?
Andrew Grimm
+1  A: 

Actually, a patch has been submitted in April 2009 to clarify gitmodule role.

So now the gitmodule documentation does not yet inlucde:

The .gitmodules file, located in the top-level directory of a git working tree, is a text file with a syntax matching the requirements -of linkgit:git-config[1].
[NEW]:
As this file is managed by Git, it tracks the +records of a project's submodules.
Information stored in this file is used as a hint to prime the authoritative version of the record stored in the project configuration file.
User specific record changes (e.g. to account for differences in submodule URLs due to networking situations) should be made to the configuration file, while record changes to be propagated (e.g. +due to a relocation of the submodule source) should be made to this file.

That pretty much confirm Jim's answer.


If you follow this git submodule tutorial, you see you need a "git submodule init" to add the submodule repository URLs to .git/config.

"git submodule sync" has been added in August 2008 precisely to make that task easier when URL changes (especially if the number of submodules is important).
The associate script with that command is straightforward enough:

module_list "$@" |
while read mode sha1 stage path
do
 name=$(module_name "$path")
 url=$(git config -f .gitmodules --get submodule."$name".url)
 if test -e "$path"/.git
 then
 (
  unset GIT_DIR
  cd "$path"
  remote=$(get_default_remote)
  say "Synchronizing submodule url for '$name'"
  git config remote."$remote".url "$url"
 )
 fi
done

The goal remains: git config remote."$remote".url "$url"

VonC
A: 

Just edit your .git/config file. For example; if you have a "common" submodule you can do this in the super-module:

git config submodule.common.url /data/my_local_common
felipec