Skip to content

Instantly share code, notes, and snippets.

@dboyliao
Last active April 13, 2016 17:09
Show Gist options
  • Save dboyliao/1ecd6dbd9bdf982d3dcbfd915745499d to your computer and use it in GitHub Desktop.
Save dboyliao/1ecd6dbd9bdf982d3dcbfd915745499d to your computer and use it in GitHub Desktop.
command for commit before fire.
git_branch_info() {
ref=$(git symbolic-ref HEAD 2> /dev/null) || ref='None';
[ "$ref" == 'None' ] && echo "None" && return;
echo "${ref#refs/heads/}"
}
fire(){
BRANCH_NAME=$(git_branch_info);
if [ "$1" == '' ]; then
MESSAGE='On fire!!';
else
MESSAGE="$1";
fi
if [ "$2" == '' ]; then
ORIGIN='origin';
else
ORIGIN="$2";
fi
if [ "$BRANCH_NAME" == 'None' ]; then
echo -e '\033[1;31mNothing to do. Run for your life!!\033[0m';
else
# commit files if there is any.
git add -A && git commit -m "$MESSAGE";
# Force push. DANGEROUS!
git push -f "$ORIGIN" "$BRANCH_NAME" && \
printf '\033[1;36mSucessfully push to github. It is about time to RUN!\033[0m' || \
printf '\033[1;31mFail to push. Leave it and RUN!!\033[0m';
fi
unset MESSAGE ORIGIN BRANCH_NAME;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment