25

I have a simple project that has one submodule.

$ git submodule
 964737623a362f6303e87ec41f2c7090c8c2c093 lib/mongodb-php-odm (heads/master-1-g9647376)

I have made changes to that submodule and committed them, but cannot push them to github.

$ cd lib/mongodb-php-odm
$ git branch
* (no branch)
  master
$ git remote -v
origin  [email protected]:colinmollenhour/mongodb-php-odm.git
$ git ls-remote .
964737623a362f6303e87ec41f2c7090c8c2c093    HEAD
6f5f91eff9b1854faa30608f335aee92aa7532eb    refs/heads/master
6f5f91eff9b1854faa30608f335aee92aa7532eb    refs/remotes/origin/HEAD
6f5f91eff9b1854faa30608f335aee92aa7532eb    refs/remotes/origin/master
$ git push origin master
Everything up-to-date

I don't understand why it says "Everything up-to-date" because the 964737 commit has not been pushed to github. It is likely I did something wrong, but I have no idea what that would be..

How do I push the latest commit in this submodule to github?

2 Answers 2

16

It seems that you committed to no branch, i.e. your commit isn't part of any branch. Create a branch where you're standing, then launch gitk to compare to master, then cherry-pick or rebase as necessary.

4
  • 9
    Thanks, that got me going in the right direction. Here are the steps I took exactly, which worked like a charm. Looks pretty simple now... git checkout -b temp; git checkout master; git merge temp; git branch -d temp; git push origin master;
    – ColinM
    Commented Dec 15, 2010 at 6:22
  • 1
    This is generally the state a submodule will be in. When a git submodule command checks out a given commit, it does so in detached HEAD mode (no branch checked out, just the specific commit).
    – Cascabel
    Commented Dec 15, 2010 at 13:28
  • 2
    what to do if you commit to no branch is a good article for solving this situation.
    – Ian Dunn
    Commented Aug 15, 2012 at 17:00
  • 2
    @ColinM, I think you should move your comment to an answer because it is the complete solution, That helped me solve the exact same problem! Thanks Commented Jan 25, 2014 at 7:11
9

@ColinM, I think you should move your comment to an answer because it is the complete solution, That helped me solve the exact same problem! Thanks – Juan Carlos Moreno

I'll do that here.

As Scheffer said, you're on a "HEAD-less" commit. As ColinM said, you can merge that commit back to master like this:

cd lib/mongodb-php-odm
git checkout master
git merge HEAD@{1}
git push origin master

EDIT: Using HEAD@{1} instead of a temporary branch or tag is simpler since there is no cleanup required. The expression HEAD@{1} means the HEAD's previous value which in this case would be the new commit on the headless branch.

2
  • Please include some explanation of what you're doing and how it solves the problem.
    – Barmar
    Commented Aug 23, 2014 at 2:59
  • 1
    @Barmar, git-submodules will checkout a specific commit, not a branch, so it leaves sub-repos with "detached heads". These steps (suggested by ColinM) merge the current commit into the master branch before pushing.
    – cdunn2001
    Commented Jan 10, 2015 at 1:43

Not the answer you're looking for? Browse other questions tagged or ask your own question.