7

I'm trying to change the remote on a submodule as per these instructions.

After modifying and saving .gitmodules, then doing git submodule sync my submodule hasn't changed, though my .git/config file has been updated to match the new remote url in .gitmodules.

I've also tried git submodule sync --recursive, and doing rm -rf .git/modules/<mySubmodule> as per this tip without any difference. In fact, running the latter command then git submodule sync again gives fatal: Not a git repository: ../.git/modules/<mySubmodule>. Any tips?

I initially added the submodule to the project via git submodule add git://<mySubmodule-url> as per the git docs.

Edit

I've even updated git via homebrew to v2.1.1, still nothing. I've also tried starting completely from scratch, and even switching between two completely different submodules but I'm still getting the same results. In sum:

$> mkdir myRepo
$> cd myRepo
myRepo$> git init .
myRepo$> git submodule add https://<path/to/my/repo>.git
myRepo$> vim .gitmodules 
# change submodule url to https://<path/to/another/repo>.git
myRepo$> git submodule sync # updates my .git/config file with the new submodule url, but all my files in the submodule are still from the old url
myRepo$> git submodule sync --recursive # doesn't do anything
myRepo$> git submodule update --init --recursive # doesn't do anything either
myRepo$> rm -rf .git/modules/<mySubmodule> # tip from SO comment linked above
myRepo$> git submodule sync
fatal: Not a git repository: ../.git/modules/<mySubmodule>
3
  • Just a git submodule update --init --recursive wouldn't work (after the git submodule sync --recursive)? Commented Sep 29, 2014 at 20:22
  • Nope--I'm still seeing the original submodule. Commented Sep 29, 2014 at 20:23
  • See stackoverflow.com/questions/3336995/… Commented Jan 23, 2017 at 18:02

1 Answer 1

9

That does seem to be annoying. Not ideal, but the following seems to work for me

git submodule foreach git pull --rebase
Sign up to request clarification or add additional context in comments.

3 Comments

Yup, that worked! Definitely not ideal but I'll take it. Can you explain your answer a bit more before I accept it? Also, were you able to replicate my problem?
I do see the same behavior with Git 2.1.1. I am honestly not sure if it is 'expected' or a bug. Submodules have always been somewhat hokey. As to why it works - it causes git to go into the submodule and do a fetch (which in my case translated to a forced branch again - again, not sure why).
@IgorGanapolsky- You might want to open up a new question with some more details. Regards

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.