When I fetch my git project that uses submodules, the submodules have a detached head. I read many posts here on stackoverflow and they say that that problem should be solved - so I'm doing something wrong, but can't detect what.
That's what happens:
M.Grunwald % git clone -b BranchName ssh://git@10.128.28.106:7999/~m.grunwald/repo_with_submodules.git some_repo
Cloning into 'some_repo'...
remote: Counting objects: 26, done.
remote: Compressing objects: 100% (26/26), done.
remote: Total 26 (delta 9), reused 0 (delta 0)
Receiving objects: 100% (26/26), done.
Resolving deltas: 100% (9/9), done.
M.Grunwald % cd some_repo
M.Grunwald % cat .gitmodules
[submodule "Library/MyLib"]
path = Library/MyLib
url = ssh://git@10.128.28.106:7999/~m.grunwald/my_lib.git
branch = BranchName
M.Grunwald % git submodule init
Submodule 'Library/MyLib' (ssh://git@10.128.28.106:7999/~m.grunwald/my_lib.git) registered for path 'Library/MyLib'
M.Grunwald % git submodule update --remote
Cloning into
'/cygdrive/c/Users/m.grunwald/Documents/TMP/some_repo/Library/MyLib'...
Submodule path 'Library/MyLib': checked out '5c665e00cca5eb24d9b615294807520a6036fa90'
git submodule update --remote 4.31s user 10.61s system 10% cpu 2:21.52 total
M.Grunwald % cd Library/MyLib
M.Grunwald % git status
HEAD detached at 5c665e0
nothing to commit, working tree clean
So, the .gitmodules contains the submodule, including "branch = branchname" and I call submodule update with --remote ... What is still missing?
% git --version git version 2.12.3
That's what happens if I switch to BranchName (cwd is some_repo/Library/MyLib):
M.Grunwald% git branch -r
origin/HEAD -> origin/master
origin/BranchName
M.Grunwald % git checkout BranchName
Branch BranchName set up to track remote branch BranchName from origin.
Switched to a new branch 'BranchName'
M.Grunwald % git status
On branch BranchName
Your branch is up-to-date with 'origin/BranchName'.
nothing to commit, working tree clean
M.Grunwald % cd ..
M.Grunwald % ..
M.Grunwald % git status
On branch BranchName
Your branch is up-to-date with 'origin/BranchName'.
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
(commit or discard the untracked or modified content in submodules)
modified: Library/MyLib (new commits)
M.Grunwald % git diff Library/MyLib
diff --git a/Library/MyLib b/Library/MyLib
index 1341b30..5c665e0 160000
--- a/Library/MyLib
+++ b/Library/MyLib
@@ -1 +1 @@
-Subproject commit 1341b30ae55df1afc7265a9110fbf09661dd627b
+Subproject commit 5c665e00cca5eb24d9b615294807520a6036fa90