Git Submodules on Heroku, A workaround

To date, git submodules do not play nicely with heroku deployments. I wrote a script for a project I maintain that may be of use to someone else. It works by first creating a deployment branch of your code in git where the submodules are just regular directories of code. When you want to deploy it does all the work of moving your changes into the directory, stripping out all the submodule stuff, and pushing up to heroku.

# Deployment script
# Why?
# One does not simply deploy git submodules to heroku!
# That's right, this is for heroku

echo "Create a build directory..."

# remove the existing build directory to start fresh
rm -rf "build"

# make a new one
mkdir "build"

# copy all files except the build directory into it
rsync -a . "build" --exclude="build" --exclude="." --exclude=".."

# change to the build directory
cd "build"

# clear out any and all modified files
git reset --hard

# we are deleting these so git won't complain when we switch branches
echo "Deleting submodule folders..."
rm -rf assets/js/base/
rm -rf theme/nitronext/

echo "Checkout the deploy branch..."
git checkout deploy
git pull heroku master

echo "Copy in new changes..."
rsync -a ../ . --exclude "build" --exclude=".git" --exclude="." --exclude=".."

# echo "Removing the .gitmodules file..."
rm .gitmodules

echo "Adding all the changes to the git index..."
git add --all

echo "Commiting..."
git commit -m 'Deployment'

echo "Deploying to Heroku..."
git push heroku deploy:master

comments powered by Disqus

© Balanced Scale Media, LLC. All right reserved.