1

Our team is using git submodules, but we run into some errors with pulling, which tells us that we are behind even though we recently updated (and there have been no remote commits / pushes since). This happens in two scenarios:

  1. with detached HEAD in our submodules, or
  2. when using git commit --amend.

I will try and show the scenarios where these things have happened. My question is, does anyone know where the specific error lies, and a simple method (better than our dirty hacks) to fix them?

Scenario 1 - Detached HEAD

  1. We issue either:
    1. git clone --recursive $REPO $DIR
    2. git sfe 'git pull origin master'
    3. git submodule update --recursive - We have actually not used this much because it tends to put us in detached HEAD state
  2. We check to see if all branches are on master (or at least not in detached HEAD state) with git sfe 'git branch'. If not, we issue a git sfe 'git checkout master'. (We are currently all (~4 people) developing on master, just to minimize having to merge and for getting up and running)
  3. If we are in detached HEAD, make changes, then later switch to master (so our unstaged files stay in the working directory), stage and commit those changes, then try to push, Git says that we must pull because we are behind. We can fix this by:
    • Saying 'screw it', checking out an entirely clean supermodule, make sure that we are not in detached HEAD, and work from there
    • Get the revision number, git checkout master, then issue a git merge $REV and go through the pain of re-merging current changes the conflict with the past changes that seem to be in there.

Scenario 2 - Amending a Commit

  1. Not much to this one. I will be developing on my own, issue a git commit --amend, then try to push those changes. However, when I do this, it tells me that I am behind and must merge. When I do, it is once again the painful process of re-merging all of the current changes with past revisions.
    • Is this because I am trying to push something that is based on a commit that is no longer the HEAD?

Note: git sfe is our alias for git submodule foreach --recursive (we have some nested submodules, just for masochism [or rather, the fact that we need to be able to separate the code out and the placement for the sub-submodule makes sense])

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
eacousineau
  • 3,457
  • 3
  • 34
  • 37
  • 1
    Note that it is normal for a submodule to be in a detached HEAD state. The main repository references a specific commit (SHA) of the submodule, not a branch or tag. One caveat is that, if you decide to actually do some development in a submodule, you need to always make sure to do the appropriate checkout or branch creation first. – twalberg Nov 20 '12 at 17:55

0 Answers0