Skip to content

Instantly share code, notes, and snippets.

@brookst
Last active October 31, 2016 18:12
Show Gist options
  • Save brookst/da1d5e437f6ec5c879d0d8963570979f to your computer and use it in GitHub Desktop.
Save brookst/da1d5e437f6ec5c879d0d8963570979f to your computer and use it in GitHub Desktop.
#!/bin/bash
# Demo pushing changes to checked out clones of a repo
# !Run in a temp dir!
set -uex
main () {
# Setup
mkdir work
pushd work
git init
echo "Initial state" > file
git add file
git commit -m "Initial commit"
git checkout -b dev
popd
git clone work testing
pushd testing
git checkout dev
git config --local receive.denyCurrentBranch updateInstead
popd
git clone work production
pushd production
git checkout master
git config --local receive.denyCurrentBranch updateInstead
popd
pushd work
git remote add testing ../testing
git remote add production ../production
popd
grep --color=auto . ./*/file
# Make a change
pushd work
echo "Modified state" > file
git commit -m "Change" file
git push testing dev
popd
grep --color=auto . ./*/file
# Finalise for production
pushd work
echo "Final state" > file
git commit -m "Change" file
git push testing dev
popd
grep --color=auto . ./*/file
pushd work
git checkout master
git merge dev
git push production master
popd
grep --color=auto . ./*/file
}
if [ "${1:-}" = "clean" ]; then
rm -rf work testing production
else
main
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment