Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change the remote repository for a git submodule?

I've created a git repository with a submodule in it. I'm able to tell the submodule itself to change its remote repository path, but I'm not sure how to tell the parent repository how to change the remote repository path for the submodule.

I wouldn't be surprised if I'm somewhat out of luck and have to do things manually, as even deleting submodules isn't easy.

like image 859
Andrew Grimm Avatar asked May 27 '09 02:05

Andrew Grimm


People also ask

How do you change the remote on a submodule?

In order to update an existing Git submodule, you need to execute the “git submodule update” with the “–remote” and the “–merge” option. Using the “–remote” command, you will be able to update your existing Git submodules without having to run “git pull” commands in each submodule of your project.

How do I change my submodule location?

Git Submodules Moving a submodule If needed, create the parent directory of the new location of the submodule ( mkdir -p new/path/to ). Move all content from the old to the new directory ( mv -vi old/path/to/module new/path/to/submodule ). Make sure Git tracks this directory ( git add new/path/to ).

Can I edit git submodule?

If you want to make a change within a submodule, you should first check out a branch, make your changes, publish the change within the submodule, and then update the superproject to reference the new commit.


2 Answers

These commands will do the work on command prompt without altering any files on local repository

git config --file=.gitmodules submodule.Submod.url https://github.com/username/ABC.git git config --file=.gitmodules submodule.Submod.branch Development git submodule sync git submodule update --init --recursive --remote 

Please look at the blog for screenshots: Changing GIT submodules URL/Branch to other URL/branch of same repository

like image 28
Pavan Sokke Nagaraj Avatar answered Oct 11 '22 05:10

Pavan Sokke Nagaraj


You should just be able to edit the .gitmodules file to update the URL and then run git submodule sync --recursive to reflect that change to the superproject and your working copy.

Then you need to go to the .git/modules/path_to_submodule dir and change its config file to update git path.

If repo history is different then you need to checkout new branch manually:

git submodule sync --recursive cd <submodule_dir>   git fetch git checkout origin/master git branch master -f git checkout master 
like image 79
Jim Puls Avatar answered Oct 11 '22 06:10

Jim Puls