Skip to content

Instantly share code, notes, and snippets.

@Mehonoshin
Created October 20, 2016 14:11
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Mehonoshin/c58f4351869b4a740530c74ce6f67093 to your computer and use it in GitHub Desktop.
Save Mehonoshin/c58f4351869b4a740530c74ce6f67093 to your computer and use it in GitHub Desktop.
Git autocommit hook
#!/usr/bin/env bash
# Drop this file to .git/hooks/post-commit
branch_name=`git symbolic-ref --short HEAD`
retcode=$?
non_push_suffix="_local"
# Only push if branch_name was found (my be empty if in detached head state)
if [ $retcode = 0 ] ; then
#Only push if branch_name does not end with the non-push suffix
if [[ $branch_name != *$non_push_suffix ]] ; then
echo
echo "**** Pushing current branch $branch_name to origin [post-commit hook]"
echo
git push origin $branch_name;
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment