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 = [email protected]: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?
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.
You can set the submodule to track a particular branch (requires git 1.8. 2+), which is what we are doing with Komodo, or you can reference a particular repository commit (the later requires updating the main repository whenever you want to pull in new changes from the module – i.e. updating the commit hash reference).
The submodule is just a separate repository. If you want to make changes to it, you should make the changes in its repository and push them like in a regular Git repository (just execute the git commands in the submodule's directory).
What steps am I missing to switch my 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.
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.
In order to remove a Git submodule from your repository, use the “git submodule deinit” command followed by the “git rm” command and specify the name of the submodule folder. $ git submodule deinit <submodule> $ git rm <submodule>
To switch to an existing branch, you can use git checkout again (without the -b flag) and pass the name of the branch you want to switch to: (my-feature)$ git checkout master Switched to branch 'master' (master)$ There is also a handy shortcut for returning to the previous branch you were on by passing - to git checkout instead of a branch name:
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.
If you want to switch to a branch you've never tracked before.
After you have changed the branch in .gitmodules
, do the following:
git submodule update --init --recursive --remote cd submodule_name git checkout new_branch_name
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With