Everettss
Everettss

Reputation: 16069

Git submodule status - how to show current branches in submodules

Checking status of submodules in main repository with this command:

git submodule status

produces output (without clear information about branches):

491e03096e2234dab9a9533da714fb6eff5dcaa7 vendor/submodule1 (v1.51.0-560-g491e030)
8bccab48338219e73c3118ad71c8c98fbd32a4be vendor/submodule2 (v1.32.0-516-g8bccab4)

Is it possible to check current branches on submodules without:

cd vendor/submodule1
git status
cd ../submodule2
git status

?

This command don't work:

git submodule status -b

Upvotes: 16

Views: 31148

Answers (2)

Bal Krishna Jha
Bal Krishna Jha

Reputation: 7286

You can run git submodule status --recursive.

It gives

  • commit id
  • path of the submodule in the project
  • branch name

Upvotes: 14

Everettss
Everettss

Reputation: 16069

Answer was hidden in git submodule foreach:

git submodule foreach 'git status'

You can always make it simpler by assign this to alias:

git config --global alias.sb "submodule foreach \"git status\""

Now git sb give you nice information about your branches in submodules:

Entering 'vendor/submodule1'
On branch master
Your branch is up-to-date with 'origin/master'.
nothing to commit, working directory clean
Entering 'vendor/submodule2'
On branch master
Your branch is up-to-date with 'origin/master'.
nothing to commit, working directory clean

Upvotes: 33

Related Questions