Git bash shows the branch name as
(master)
But when using submodules, it now shows the hash and not the name, for example:
((445c03f...))
How can I make it show the name of the branch while inside a submodule?
Rule for beginners: Submodules don't use branch names. Rule for advanced Git users: Submodules don't use branch names yet. 😀 (See link to glean the meaning of the word yet here.)
As the answer that phd linked to in a comment noted, Git submodules are normally in detached-HEAD mode. What you see—the hash ID of the detached HEAD—when you enter the submodule is reality. Showing a branch name here might be a beautiful illusion, but beware beautiful illusions: they may cause you to walk along a pretty, yellow brick road that actually simply drops off a cliff.
The general idea here is that it's the superproject commit that dictates what should be checked out. This is, after all, the case with the superproject's files: if you git checkout a123456
in the superproject, you get all the files that go with commit a123456
.1 If that commit requires commit b789abc
in submodule sub/mod
, should not sub/mod
have commit b789abc
also checked out?2
The actual implementation of all of this, in Git, has major rough edges. It puts me in mind of a shop full of power tools that lack safety guards. The git submodule update
command can make use of branch names, but the ways it does make use of branch names are confusing (sensible in certain contexts, but confusing). If you want to use submodules, try to treat them as read-only "get this commit from this repository" operations as much as possible, because that's what Git tends to do with them.
1Well, that is, as long as we are not playing clever index and working tree tricks, as seen in Checkout another branch when there are uncommitted changes on the current branch.
2And yet, unless you use --recursive
or set various options, git checkout
doesn't check out b789abc
automatically: you have to run git submodule update
. Setting the recursive option makes this—by this I mean git checkout
/ git switch
—behave well, but because submodules are so rigid and fragile and messy, I don't really like setting the recursive option.