Changing an existing submodule's branch

Go into the directory where the submodule resides and git checkout the correct branch/commit. Then go up one level and git add and git commit the directory. This will check in the submodule with the correct commit.

And don't forget to run git submodule update --recursive on the other clients after updating them.


The answer above (@milgner) didn't work me (git version 2.17.0). Maybe I did something wrong.

The below is what worked for me:

nano .gitmodules # substitute the needed branch here
git submodule update submodule_name # update the submodule
git add .gitmodules && git commit -m 'some comment' # add and commit
git submodule status # check that changes have been applied