I am running git on windows 8.1, and pulling from upstream using the following batch script:
git pull --recurse-submodules
git submodule update --recursive --remote --init --merge
git submodule foreach "git pull || true"
I know that it is redundant, but trial and error showed that sometimes any one of the above commands would not fetch something that the others would, so after battling with it for a while, and reading different answers on SO, I gave up and went with the "belt and suspenders" approach.
This worked reasonably well for about a year, until a week ago I updated to git version 2.18.0.windows.1
Since then, almost every invocation results in a detached head in some of the submodules. I go into the problematic ones, git checkout
the correct branch, do a git pull
from inside the submodule and everything looks fine, but if I try to run the script again for in main repo, BAM! same submodules get into a detached head state even if nothing changed upstream and nothing was pulled.
The only thing I am aware of that changed is the git version.
What am I doing wrong and what is the right way?
Edit:
The project is set up, submodules are used for files that are shared between multiples repos, and those files are changed regularly by developers (no, I don't have a say in it).
What I am trying to accomplish is to get the latest commits for the repositories on their checkoed-out branches, and then update the superproject pointer and push to origin.
Edit 2:
Will the following do what I intend above?
git pull
git submodule foreach "git pull || true"