Skip to content

Instantly share code, notes, and snippets.

@davidsmalley
Created December 3, 2009 10:55
Show Gist options
  • Save davidsmalley/248066 to your computer and use it in GitHub Desktop.
Save davidsmalley/248066 to your computer and use it in GitHub Desktop.
# Find the current branch name without any textual adornments
function lparse_git_branch {
git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/'
}
# Override git so we can check the branch name
function git () {
GIT="`which git`"
if [[ "$1" == "commit" ]]; then
if [[ $(lparse_git_branch) == "staging" || $(lparse_git_branch) == "production" ]]; then
echo "Note: Please don't commit directly to production or staging.
Change to master or a topic branch and try again.
<resetting commit>"
$GIT reset HEAD
return 1
else
$GIT $*
fi
else
$GIT $*
fi
}
# Usage
# (in git repo dir)
# litgit production commit -v -a
# (runs normal commit)
# (switches to branch named in 2nd arg)
# (runs rebase against original branch)
# (switches back to original branch)
function litgit () {
GIT="`which git`"
if [[ "$2" == "commit" ]]; then
CBRANCH=$1
ARGS=$(echo $* | sed -e 's/^ *[^ ]* //')
BRANCH=$(lparse_git_branch)
$GIT $ARGS
$GIT checkout $CBRANCH
$GIT rebase $BRANCH
$GIT checkout $BRANCH
echo "*** Check above to verify that we commited to master and production - if so you can now push and deploy ***"
return 0
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment