git: change origin of cloned submodule

I created a project submodule and put it up on Github.

I created another project, supermodule, and then did this:

cd supermodule
git init
mkdir lib
git clone git:// lib/submodule
git submodule add ./lib/submodule lib/submodule

This worked fine, but on the website, it can’t find the link to the submodule when viewing the files (in fact it just says “Loading Commit data” forever). The submodule folder itself has the correct origin.

Apparently, what I should have done was

mkdir lib
git submodule add git:// lib

…but it’s too late for that now. How can I have the submodule in this project correctly point to origin?

  • How to prevent git pull from overwriting a file?
  • Checkout branch in Git Extensions creates branch with uppercase name
  • Is an SSH Key Required to clone a public github account?
  • Github-plugin for Jenkins get committer and author name
  • Resetting changes to previous commit, without creating a new commit
  • Protecting Info on Github
  • Push to remote on GitHub pointed to a new server IP instead
  • Using Bundler with Git, is https:// or git:// better?
  • One Solution collect form web for “git: change origin of cloned submodule”

    This apparently is very much dependent on the version of git you are using.

    1. If present, change the url entry in the [submodule "<dirname>"] section of the .gitmodules file.
    2. If present, change the url entry in the [submodule "<dirname>"] section of the .git/config file.
    3. Change the url in the configuration of the submodule itself. The location of the config file is version dependent. Older versions had it in <dirname>/.git/config, newer ones in .git/modules/<dirname>/config. However, you can always use below command:
    cd <dirname>
    git config remote.origin.url <new_url>
    Git Baby is a git and github fan, let's start git clone.