mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Bryce Glover <>
Subject: Automatically Handling Using/Checking Out Branches With One or More Different Contained Submodules?
Date: Tue, 24 Aug 2021 08:00:00 -0400	[thread overview]
Message-ID: <> (raw)
In-Reply-To: <>

(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

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
<>.  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

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

  git submodule sync && git submodule update --init

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?

     Bryce Glover, an amateur Git user

       reply	other threads:[~2021-08-24 12:01 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <>
2021-08-24 12:00 ` Bryce Glover [this message]
2021-08-27 22:48   ` Automatically Handling Using/Checking Out Branches With One or More Different Contained Submodules? Philippe Blain
2021-08-28  1:23     ` Bryce Glover

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:

  List information:

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='' \ \ \

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).