git: change origin of cloned submodule
Asked Answered
C

2

46

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://github.com/tandu/submodule 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://github.com/tandu/submodule lib

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

Crept answered 25/4, 2012 at 14:21 Comment(0)
K
75

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>
Kinin answered 25/4, 2012 at 15:34 Comment(1)
with the current version of git (2.1.0), doing git submodule sync --recursive was enough for me to update to submodule origin remote.Laborer
B
21

In other question I found answer for more modern Git version (2.25)

git submodule [--quiet] set-url [--] <path> <newurl>

Let's assume that you have submodule in directory external/foo-lib which origins is https://github.com/example-user/foo-lib.git and you want to change it to yours fork https://github.com/your-account/foo-lib.git then in root directory of git project type:

git submodule set-url external/foo-lib https://github.com/your-account/foo-lib.git

Backtrack answered 6/2, 2021 at 1:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.