git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Automatically Handling Using/Checking Out Branches With One or More Different Contained Submodules?

From
BGBryce Glover <randomdsdevel@gmail.com>
Date
Aug 24, 2021, 12:00 UTC
Message-ID
<CALH-JHvKjK7KU+Z_R7kG291DQKyb3f=LwxcbP4fn-qL2eeosBQ@mail.gmail.com>
In-Reply-To
<CALH-JHvNHVvPWap8eiMaQ6HAJOBa4W5xuA9V_s7zPLubgwaRow@mail.gmail.com>

(Note: If this question would fit better on the git-users Google Group, I apologize, but I saw that, unlike there — unless I overlooked something? —, you could send messages here even if you weren't a list subscriber.)

To whom it may concern,
     Currently, the only method I've seen that you can reliably use to
switch between different branches when they don't all have the same
contained submodules comes from the Stack Overflow answer at
<https://stackoverflow.com/a/64690495/3319611>.  I'll reproduce the
Bash snippet it presents as a solution here for completeness's sake:
```
export TARGET_BRANCH="my-branch-name"
export CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
if [ -f ".gitmodules" ]; then
  git submodules deinit --all
  mkdir -p .git/git-tools/modules
  mv .git/modules .git/git-tools/modules/$CURRENT_BRANCH
fi
git checkout $TARGET_BRANCH
if [ -f ".gitmodules" ]; then
  if [ -f ".git/git-tools/modules/$TARGET_BRANCH" ]; then
    git mv .git/git-tools/modules/$TARGET_BRANCH .git/modules
  fi
  git submodule sync && git submodule update --init
fi
```

This involves invoking some actions before '`git checkout`,' so I couldn't have a couple of Git hooks handle this since, per '`git help hooks`,' Git doesn't implement a 'pre-checkout' hook, only a post-checkout one. That wouldn't be enough of a use case to motivate adding that, though, would it? Alternatively, '`git checkout`' would, ideally, handle this automatically, perhaps when requested by flag if it wouldn't make sense for this behavior to be the default one. I don't know if I'd personally be up to contributing either one or both of either of those approaches, at least not right away, but, hypothetically, how involved might that turn out to be?

Curious,
     Bryce Glover, an amateur Git user
     RandomDSdevel@gmail.com
Next: Philippe Blain
Message 1 of 3 in “Automatically Handling Using/Checking Out Branches With One or More Different Contained Submodules?”
  1. Bryce GloverAug 24, 2021
  2. Philippe BlainAug 27, 2021
  3. Bryce GloverAug 28, 2021

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.