Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git submodule sync doesn't work

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>
like image 440
acannon828 Avatar asked Sep 29 '14 20:09

acannon828


People also ask

What does git submodule sync do?

git submodule sync synchronizes all submodules while git submodule sync -- A synchronizes submodule "A" only. If --recursive is specified, this command will recurse into the registered submodules, and sync any nested submodules within.

How do I manually add a git submodule?

In order to add a Git submodule, use the “git submodule add” command and specify the URL of the Git remote repository to be included as a submodule. When adding a Git submodule, your submodule will be staged. As a consequence, you will need to commit your submodule by using the “git commit” command.

What is git submodule update -- init -- recursive?

git submodule update --init --recursive --remote - updates all submodules recursively along their tracking branches. Without the --remote , it'll reset the submodule working directories to the "right" commit for the parent.


1 Answers

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

git submodule foreach git pull --rebase
like image 99
Andrew C Avatar answered Oct 30 '22 08:10

Andrew C