I have a repository with one submodule:
$ cat .gitmodules
[submodule "foo"]
path = foo
url = https://gitlab.xx.yy/zz/foo.git
branch = xxxAfter I clone the main repo and run "git submodule init" + "git submodule update", the submodule is in a detached state: $ (cd foo && git status) HEAD detached at cb52389b nothing to commit, working tree clean
I was expecting it to be on the branch spelled out in the configuration, but I guess this is working as designed: that's the correct commit, so nothing to worry about yet.
At this point, if I create a stash in the main repo with -m, the stash comment correctly says it was on master: $ git stash -m "test prestazioni filtri RFID" Saved working directory and index state On master: test prestazioni filtri RFID
$ git stash list
stash@{0}: On master: test prestazioni filtri RFIDNow I explicitly check out the submodule by branch name, in preparation for work in the submodule itself: $ (cd foo && git checkout xxx) Switched to branch 'xxx' Your branch is up to date with 'origin/xxx'.
$ (cd foo && git log -1) commit cb52389b (HEAD -> xxx, origin/xxx) Author: Flavio Stanchina [...]
I create a stash in the main directory with exactly the same command as before: $ git stash -m "test prestazioni filtri RFID" Saved working directory and index state On xxx: test prestazioni filtri RFID
$ git stash list
stash@{0}: On xxx: test prestazioni filtri RFIDAs you can see, the stash took the branch name from the submodule (there is no branch with that name in the main repo, and it's still on master anyway).
This doesn't happen if I just run "git stash" without -m: $ git stash Saved working directory and index state WIP on master: 7bf81a83 [...]
$ git stash list
stash@{0}: WIP on master: 7bf81a83 [...]Is this expected? I don't think so.
Am I not supposed to touch the submodule directory in any way? Even if that's the case, why would it make sense to pick the branch name from the submodule when stashing in the main directory?
Running on Debian 11 in a WSL instance: $ git --version git version 2.30.2
$ dpkg -s git ... Version: 1:2.30.2-1 ...
-- Ciao, Flavio