DEV Community

Serhat Teker
Serhat Teker

Posted on • Originally published at tech.serhatteker.com on

Changing Git Submodule Repository to other URL/Branch

List the details in .gitmodules file

$  git config --file=.gitmodules -l
Enter fullscreen mode Exit fullscreen mode

This command lists all the submodules present in the current repository with their paths, URL location and the branch which it is mapped in the repository.

Output will be like:

submodule.themes/hugo-coder.path=themes/docker
submodule.themes/hugo-coder.url=https://github.com/user/coder.git
submodule.themes/hugo-coder.branch=docker
Enter fullscreen mode Exit fullscreen mode

Edit the Submodule URL

This command will edit the URL of the submodule and will place it with the specified new URL repository.

$  git config --file=.gitmodules submodule.Submod.url https://github.com/username/ABC.git
Enter fullscreen mode Exit fullscreen mode

Edit the Submodule Branch

$  git config --file=.gitmodules submodule.Submod.branch development
Enter fullscreen mode Exit fullscreen mode

This command will edit the Branch docker of the submodule and will place it in the specifified Branch development.

Sync and update the Submodule

$  git submodule sync
$  git submodule update --init --recursive --remote
Enter fullscreen mode Exit fullscreen mode

These commands will sync and update the submodule to the newly specified branch or URL successfully.

Top comments (0)