Git submodule url changed
Asked Answered
U

2

6

I have a Git project which has a submodule. The url of the submodule was recently changed. I have changed the .gitmodules and config file to point to the new url. Should I commit the .gitmodules file so that the next time I checkout my project and do git submodule update --init --recursive I won't get an error?

Unbridle answered 9/3, 2016 at 21:23 Comment(4)
Possible duplicate of Changing remote repository for a git submoduleOberammergau
I read that. Nobody speaks about how and what files one has to commit.Unbridle
"You should just be able to edit the .gitmodules file to update the URL and then run git submodule sync to reflect that change to the superproject and your working copy." If this doesn't answer your question, please clarify the question and explain what exactly the problem is.Oberammergau
What steps have to be followed after this? Should I commit the changes done to .gitmodule?Unbridle
O
2

Yes, after editing .gitmodules, you should commit and push those changes, so the change becomes available to everyone. Otherwise, only your local submodule would point to the new URL and everyone else would still the old URL.

However, you don't need to commit to change the URL locally, git will also switch to the new URL if you haven't committed the change.

Oberammergau answered 9/3, 2016 at 22:48 Comment(0)
C
20

Nobody speaks about how and what files one has to commit

No need to change a file, sync/commit: this is now done for you in one new command.

With Git 2.25 (Q1 2020), "git submodule" learned a subcommand "set-url".

See commit 26b0610 (29 Oct 2019) by Denton Liu (Denton-L).
(Merged by Junio C Hamano -- gitster -- in commit 99c4ff1, 10 Dec 2019)

submodule: teach set-url subcommand

Signed-off-by: Denton Liu

Currently, in the event that a submodule's upstream URL changes, users have to manually alter the URL in the .gitmodules file then run git submodule sync.
Let's make that process easier.

Teach submodule the set-url subcommand which will automatically change the submodule.$name.url property in the .gitmodules file and then run git submodule sync to complete the process.

The git submodule documentation now includes:

set-url [--] <path> <newurl>:

Sets the URL of the specified submodule to <newurl>.
Then, it will automatically synchronize the submodule's new remote URL configuration.

Corron answered 16/12, 2019 at 21:31 Comment(0)
O
2

Yes, after editing .gitmodules, you should commit and push those changes, so the change becomes available to everyone. Otherwise, only your local submodule would point to the new URL and everyone else would still the old URL.

However, you don't need to commit to change the URL locally, git will also switch to the new URL if you haven't committed the change.

Oberammergau answered 9/3, 2016 at 22:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.