gitgit-submodules

Changing an existing submodule's branch


When I initially added my submodule, I specified a particular branch, as seen in the .gitmodule file:

[submodule "externals/grpc/grpc"]
    path = externals/grpc/grpc
    url = git@github.com:me/grpc.git
    branch = release-1.0

I want to change to the master branch of my submodule, so I changed the branch in .gitmodules from release-1.0 to master, and for good measure, just deleted the submodule from my parent git tree:

cd $submodules
rm -rf grpc
cd $gitroot
git submodule sync
git submodule update --init --recursive

Now, when I go back to my submodule, it's still checked out from a commit on the release-1.0 branch, not the latest master commit.

What steps am I missing to switch my submodule's branch?


Solution

  • 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.