0

Is it possible to create a git submodule that will always reflect the HEAD of the remote branch? i.e I don't want to have to manually update the reference to a commit. When I clone my parent repo, I want to get the HEAD of the branch the submodule is tracking. If there is a change to the submodule, but no changes to the parent repo, I want a git pull to update the submodule.

Is this possible?

ewok
  • 20,148
  • 51
  • 149
  • 254
  • Possible duplicate of [Git submodules: Specify a branch/tag](https://stackoverflow.com/questions/1777854/git-submodules-specify-a-branch-tag) – phd Sep 20 '17 at 00:19

1 Answers1

1

That's not possible: the parent repository stores the commit id of the submodule. This ensures that everyone who checks out a particular revision of the parent repository gets the same version of the submodule; the alternative would be messy (what if the submodule were updated such that it was no longer compatible with the parent repository?).

If you have to do this regularly, you could wrap it up in a script:

#!/bin/sh

submodule=$1

(cd $submodule && git checkout master && git pull)
git add -u $submodule
git commit -m "updated submodule $submodule"

Name it something like "git-update-submodule" and place it in your $PATH, and then to update a submodule in directory foo you can run:

git update-submodule foo
larsks
  • 277,717
  • 41
  • 399
  • 399