Skip to content

Instantly share code, notes, and snippets.

@chx
Created June 28, 2014 07:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chx/f80df73cfc664262ace1 to your computer and use it in GitHub Desktop.
Save chx/f80df73cfc664262ace1 to your computer and use it in GitHub Desktop.
function git() {
# Path to the `git` binary
GIT="/usr/bin/git"
# Sanity check
if [ ! -f ${GIT} ]
then
echo "Error: git binary not found" >&2
return 255
fi
# Command to be executed
command=$1
# Remove command from $@ array
shift 1
# Check command against list of supported commands
case $command in
"cd")
cd $(git rev-parse --show-toplevel)/${1}
;;
"push")
if [ -z "$1" ]
then
$GIT push || $GIT push -u origin $($GIT rev-parse --abbrev-ref @)
else
$GIT ${command} "$@"
fi
;;
*)
# Execute the git binary
$GIT ${command} "$@"
;;
esac
# Return something
return $?
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment