Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Branch-aware git submodules
#!/bin/bash
set -x
cd /tmp/
rm -rf submodules/
mkdir submodules
cd submodules/
# create component repositories
mkdir component_A
cd component_A
echo "initial commit" > a
git init
git checkout -b dev
git add a
git commit -a -m "dev commit"
git branch 3.11
cd ..
mkdir component_B
cd component_B
git init
echo "initial comit" > b
git add b
git commit -a -m "dev commit"
git branch 3.11
cd ..
# simulate some parallel work on development branch and release branch
cd component_A
echo "work on development" >> a
git commit -a -m "work on development"
git checkout 3.11
echo "work on release" >> a
git commit -a -m "work on release"
cd ..
cd component_B
echo "work on development" >> b
git commit -a -m "work on development"
git checkout 3.11
echo "work on release" >> b
git commit -a -m "work on release"
cd ..
# now make the superproject
mkdir superproject
cd superproject/
git init
git submodule --branch dev add ../component_A/ component_A
git submodule --branch master add ../component_B/ component_B
git submodule update --remote
git submodule status
cat .gitmodules
git commit -a -m "Nightly build 345"
git tag "master-nightly-345"
# make the release branch of the superproject
git checkout -b 3.11
# edit .gitmodules
sed -i "s/dev/3.11/" .gitmodules
sed -i "s/master/3.11/" .gitmodules
cat .gitmodules
git submodule update --remote
git submodule status
git commit -a -m "3.11 build 5"
git tag "3.11-nightly-5"
# test recusrive checkout
cd ..
git clone --recursive superproject superproject_clone -b master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment