Skip to content

Instantly share code, notes, and snippets.

@Kangaroux
Last active February 28, 2018 04:58
Show Gist options
  • Save Kangaroux/a7f2d302d3e2c4747128b991e6b5aca9 to your computer and use it in GitHub Desktop.
Save Kangaroux/a7f2d302d3e2c4747128b991e6b5aca9 to your computer and use it in GitHub Desktop.
Tons of shortcuts for git commands, python
#!/bin/bash
# NOTE: If you use a git remote that's named something other than "origin",
# you will need to edit the $GIT_REMOTE var below:
GIT_REMOTE="origin"
git_add() {
if [ $# = 0 ]; then
git add -A
else
git add $*
fi
}
git_add_untracked() {
if [ $# = 0 ]; then
git add -u .
else
git add -u $*
fi
}
git_commit() {
if [ $# = 0 ]; then
git commit
else
git commit -m "$*"
fi
}
git_push() {
if [ $# = 0 ]; then
git push $GIT_REMOTE $(git_current_branch)
else
git push $GIT_REMOTE $1
fi
}
git_push_remote() {
if [ $# = 0 ]; then
git push -u $GIT_REMOTE $(git_current_branch)
else
git push -u $GIT_REMOTE $1
fi
}
git_reset() {
if [ $# = 0 ]; then
git reset .
else
git reset $*
fi
}
git_current_branch() {
git rev-parse --abbrev-ref HEAD
}
git_checkout() {
git checkout -b $1 master
}
git_pull() {
if [ $# = 0 ]; then
git pull $GIT_REMOTE $(git_current_branch)
else
git pull $GIT_REMOTE $1
fi
}
git_fetch() {
git fetch $GIT_REMOTE $1
git checkout $1
}
unset GIT_REMOTE
#################################
# Git aliases
#################################
alias g="git status"
alias ga=git_add
alias gau=git_add_untracked
alias gc=git_commit
alias gd="git diff"
alias gds="git diff --staged"
alias gl="git log"
alias gp=git_push
alias gpu=git_push_remote
alias gr=git_reset
alias gct=git_checkout
alias gpl=git_pull
alias gf=git_fetch
#################################
# Python aliases
#################################
alias p="python3"
alias pm="python manage.py"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment