How to modify submodule of forked repository
I tried to modify an open source project, so I forked it.
However I met something weird when I changed to the modified branch.
My project can’t access to the new branch and I didn’t know why.
I realized that the name of the forked repository was different to the open source project I was using.
When I entered the folder containing I would modify, moved to another repository.
It is submodule, and the project has submodules for android, iOS.
Today I will show you how to modify submodules of your repository.
Submodule
I could see which submodules are in the repository them with this commands.
git submodule status
In my case, I found my forked project has two submodules, android/common and ios/common.
If you wonder which repository is linked to submodules, see .gitmodules file.
.gitmodules example
[submodule "ios-common"]
path = ios/common
url = https://github.com/darron1217/background-geolocation-android.git
[submodule "android-common"]
path = android/common
url = https://github.com/darron1217/background-geolocation-android.git
update
I tried to see submodules’ source, however both folders were empty.
What’s wrong?
To checkout submodules, we need to run this command.
git submodule update — init --remote
Then you can see the submodules are checked out.
Branch
I wanted to the android-common submodule with my forked repository.
And I hope to use specific branch.
open .gitmodules and modify url and branch like this.
.gitmodules
and run submodule update again
Deinit
If you want remove submodules, run this command.
This command will remove your all submodules.
git submodule deinit --all
However the command never modify .gitmodules.
Cautions
If you want to open your repository for NodeJS users, you should commit entire sources without submodules.
Or you have to publish a new npm project with all source.