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.

  • Change the GIT root directory on a Windows computer
  • In git, how do I create a single patch for the last 2+ revisions?
  • SmartGit log documentation?
  • Git commits are duplicated in the same branch after doing a rebase
  • Git: How to revert my local branch to the remote branch state?
  • Understanding git reset --mixed
  • 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.


    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>

  • git checkout branch but remains in master
  • git rebase branch with all subbranches
  • gitignore not working (reason found) using gitextensions in visual studio
  • Reuse a Part of a git Repository
  • Git can't clone repository
  • Git: File Rename
  • One Solution collect form web for “git submodule sync doesn't work”

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

    git submodule foreach git pull --rebase
    Git Baby is a git and github fan, let's start git clone.