Skip to content

Instantly share code, notes, and snippets.

@squarelover
Created October 17, 2014 19:10
Show Gist options
  • Save squarelover/7e5095de0f5866f25eaa to your computer and use it in GitHub Desktop.
Save squarelover/7e5095de0f5866f25eaa to your computer and use it in GitHub Desktop.
Git Aliases that cam make push and pull easier.
#
# Will return the current branch name
# Usage example: git pull origin $(current_branch)
#
function current_branch() {
ref=$(git symbolic-ref HEAD 2> /dev/null) || \
ref=$(git rev-parse --short HEAD 2> /dev/null) || return
echo ${ref#refs/heads/}
}
function current_repository() {
ref=$(git symbolic-ref HEAD 2> /dev/null) || \
ref=$(git rev-parse --short HEAD 2> /dev/null) || return
echo $(git remote -v | cut -d':' -f 2)
}
# these aliases take advantage of the previous function
alias ggpull='git pull origin $(current_branch)'
compdef ggpull=git
alias ggpur='git pull --rebase origin $(current_branch)'
compdef ggpur=git
alias ggpush='git push origin $(current_branch)'
compdef ggpush=git
alias ggpnp='git pull origin $(current_branch) && git push origin $(current_branch)'
compdef ggpnp=git
# You can replace the origin with an ENV variable, such as $CURRENT_FORK or have it read from a value in .git/config
# Let me know if you need more help with building you git tools.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment