19

I have a repository with various nested submodules. Committing and pushing works pretty well and the changes are visible at GitHub as expected.

In the testing/production environments, new releases of this project are being deployed using these commands:

git pull --recurse-submodules
git submodule update --init --recursive

But this only updates the root project, none of the submodules are updated to the commits associated with the HEAD at GitHub. So far the only way I have found to update the whole project is to run git pull inside each individual submodule folder.

I understand that git submodule update is the method referenced in most places, but it is not really producing any results in this case. What could be the cause?

Luís de Sousa
  • 5,765
  • 11
  • 49
  • 86

3 Answers3

26

You need to make sure your submodules are following a branch, or they will only be checked out at a specific SHA1 (not at the latest of a branch, but the special entry of the index of your parent repo)

See "Git submodules: Specify a branch/tag" in order to make your submodule follow a branch.

Then a git submodule update --init --recursive --remote would be enough to check out the latest from that branch.

This (git submodule update --remote) requires git 1.8.2+ March 2013. The OP Luís de Sousa has a git 1.7.9.5 (March 2012) which doesn't offer this feature. 

BenG
  • 17
  • 3
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • I tried to follow the instruction in that link, but when I issue the track command `git checkout -b master --track origin/master` I get an error message: `fatal: A branch named 'master' already exists.`. This happens in all the submodules of the project. – Luís de Sousa Jul 09 '14 at 06:42
  • @LuísdeSousa that makes sense. Try `git branch -u origin/master master` – VonC Jul 09 '14 at 06:43
  • 1
    Ok, I overlooked that, you might want to edit that answer to make that section clearer. I went on with those instructions, setting all submodules in the hierarchy to track a specific branch and then committed and pushed the main project. But to deploy it, the command `git submodule update --recursive --remote` does not seem to be valid. I am using git 1.7.9.5 and it does not have the `--remote` flag for the `submodule update` command. – Luís de Sousa Jul 09 '14 at 07:23
  • 1
    @LuísdeSousa yes, I have edited my old answer I was referring to. And yes, I have added the git version requirement (git 1.8.2+, March 2013). 1.7.9.5 (March 2012, more than 3 years ago) is indeed a bit old. – VonC Jul 09 '14 at 07:27
  • 1
    So basically the answer is that I am using a too old version of git. Please add this to your answer and will accept it. Thanks for the diligence. – Luís de Sousa Jul 10 '14 at 07:14
2

You have a specific version committed to your repository. For git the submodules are "files" containing a sha1-hash of the version you provided. git submodule update --init --recursive ensures that your submodule is available in exactly that version.

For example:

  • You make a git init on a directory and have a empty repo
  • You add a submodule using git submodule add which will record the current masters sha1-hash of that repo you are adding in your own repository
  • Multiple commits are made to the submodule but your repo will still contain that one hash you had as you added the submodule
  • If you make a git pull in the submodule you will get the new commits and have an uncommitted change in your own repository (the new sha1-hash of the submodules master)
  • As soon as you commit that change you are "pinning" the current version of the submodule
  • git submodule update will now enforce the new version is there

So if some other contributor of your own repository updates his checkout and does a git submodule update he will get the version you pinned. So in general the submodule update will do some work only when the submodule is not checked out or if someone changed the associated hash in your repository.

Knut
  • 1,792
  • 13
  • 9
0

adding the repo as submodule manually worked for me

[submodule "openpoints"]
    path = openpoints
    url = http://github.com/guochengqian/openpoints.git

in order to add the above submodule, I have called

git submodule add http://github.com/guochengqian/openpoints.git openpoints
smoothumut
  • 3,423
  • 1
  • 25
  • 35