This write-up will provide the method for changing the GitHub repository for a Git submodule.
How to Change the GitHub Repository for a Git Submodule?
To change the GitHub repository for a submodule in Git:
- First, navigate to the desired local repository that contains the submodule.
- Then, switch to the submodule and check its remote URL.
- Next, move back to the parent repository and execute the βgit submodule set-url <submodule-name> <new-remote-url>β command to change the submoduleβs remote URL.
- Finally, navigate to the submodule again and verify the new remote URL.
Step 1: Move to Local Repository
First, enter the βcdβ command along with the particular repository path that contains a submodule and switch to it:
Step 2: List Repository Content
Next, display the content of the current directory:
It can be observed that the working repository contains one submodule named βsubModβ:
Step 3: Navigate to Submodule
Then, utilize the following command along with the submodule name and move to it:
Step 4: Check Remote URL
Execute the below-listed command to check the remote URL of the submodule:
According to the given output, the submodule is linked to the remote repository with the given remote URL:
Step 5: Move Back to Parent Repository
Switch back to the present repository using the following command:
Step 6: Change Remote URL of Submodule
Now, run the βgit submodule set-urlβ command along with the module name and new remote URL:
Here, βsubModβ is the submodule name:
Step 7: Switch to Submodule
Navigate to the submodule again to view new changes:
Step 8: Verify Remote URL
Lastly, ensure whether the Git submoduleβs remote repository has changed or not by running the given-provided command:
It can be seen that the remote repository of the submodule has been changed with the new URL:
We have explained the procedure for changing the GitHub repository for a submodule.
Conclusion
To change the GitHub repository for a Git submodule, first, move to the desired local repository containing the submodule. Then, run the βgit submodule set-url <submodule-name> <new-remote-url>β command. Next, navigate to the submodule and ensure the new remote repository by typing out the βgit remote -vβ command. This article demonstrated the method of changing the GitHub repository for a Git submodule.