Skip to content

Instantly share code, notes, and snippets.

@n-st
Last active January 3, 2016 07:29
Show Gist options
  • Save n-st/8430010 to your computer and use it in GitHub Desktop.
Save n-st/8430010 to your computer and use it in GitHub Desktop.
Git post-receive hook to rebase dev branch onto master (if no changes have been made to the working copy)
#!/bin/bash
cd ..
GIT_DIR='.git'
while read oldrev newrev ref
do
if [ "$ref" != "refs/heads/dev" ]
then
echo -e "\e[33mPushed branch isn't 'dev'. Skipping rebase dev->master.\e[0m"
exit 1
fi
done
if ! git diff --quiet
then
echo -e "\e[31mWorking copy has been changed:\e[0m"
git status
exit 1
fi
if git rebase dev master
then
echo -e "\e[32mSuccessfully rebased 'dev' onto 'master'.\e[0m"
else
echo -e "\e[31mRebasing 'dev' onto 'master' failed.\e[0m"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment