1

I am relatively new to git submodules.

I know that parent repo tracks particular commit of submodule so I make a change in my submodule I have to explicitly update the commit id and push it to server. I feel this is a burden on me as a developer.

How do tell git to always track master branch of my submodule? I have already set up repo and added submodule.

username_4567
  • 4,737
  • 12
  • 56
  • 92
  • 1
    Essentially, you can use `--remote` with your `git submodule update` command which tells `git` to use remote head instead of ref recorded in your repo. In general though, if your every operation would be like that, wouldn't it be tad hard to agree on the same tree at any different time across locations? – Ondrej K. Sep 05 '19 at 09:04
  • @OndrejK. In my case, it doesn't really matter. The steps suggested above are for the local tree but whever someone new checks out my repo, he would still get the committed commit ID and not HEAD. – username_4567 Sep 05 '19 at 09:44
  • The only thing I can think of is using a git hook to update the submodule when you `git pull`, possibly using the `post-merge` git hook. EDIT: Here is a sample: https://gist.github.com/ejmr/453edc19dd596e472e90 – ikkentim Sep 05 '19 at 10:12
  • *How do tell git to always track master branch of my submodule?* Using `git submodule add --branch` or `git submodule set-branch`. But this doesn't make submodules to always checkout the branch: submodules still be [in the detached HEAD state](https://stackoverflow.com/a/53890409/7976758). There is no way around that, that how submodules were designed and work. *whever someone new checks out my repo, he would still get the committed commit ID and not HEAD* Teach them use `git submodules update --remote`. – phd Sep 05 '19 at 11:00
  • 1
    Possible duplicate of [How to setup submodule so that git clone --recursive always takes master of submodule](https://stackoverflow.com/questions/35402999/how-to-setup-submodule-so-that-git-clone-recursive-always-takes-master-of-subm) – phd Sep 05 '19 at 11:00
  • https://stackoverflow.com/search?q=%5Bgit-submodules%5D+always+track+branch – phd Sep 05 '19 at 11:00

0 Answers0