DEV Community

Serhat Teker
Serhat Teker

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

7 2

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)

👋 Kindness is contagious

Explore a sea of insights with this enlightening post, highly esteemed within the nurturing DEV Community. Coders of all stripes are invited to participate and contribute to our shared knowledge.

Expressing gratitude with a simple "thank you" can make a big impact. Leave your thanks in the comments!

On DEV, exchanging ideas smooths our way and strengthens our community bonds. Found this useful? A quick note of thanks to the author can mean a lot.

Okay