adrelanos
adrelanos

Reputation: 1593

How to list git submodules that have not been pushed to origin?

Sometimes I forget to push a git submodule. Is there a way to show which git submodules are ahead of origin, that have not been pushed?

Upvotes: 4

Views: 860

Answers (1)

VonC
VonC

Reputation: 1324957

A simple status on each submodules could give you a good representation of their respective state:

git submodule foreach "git status || true"

See "Use git submodule foreach with function" for more sophisticated scripts to run in combination of a git submodule foreach command.

That will show push status only if:

  • your module is configured to follow a branch. (Otherwise, a submodule is checked out as a detached head, and the commit status would be empty, the push status non-existent)

    git config -f .gitmodules submodule.<path>.branch <branch>
    git submodule update --init --remote
    
  • a branch has been checked out (and commits done)

    cd asubmodule
    git checkout master
    # add and commit
    

(See "Git submodule is in “detached head” state after cloning and submodule update")

Then the command would work (for instance for the 'compose' submodule of the project b2d):

VonC@voncvb MINGW64 /c/Users/VonC/prog/b2d (master)
$ git submodule foreach "git status || true"
Entering 'compose'
On branch master
Your branch is ahead of 'origin/master' by 1 commit.
  (use "git push" to publish your local commits)
nothing to commit, working directory clean

Upvotes: 4

Related Questions