Skip to content

Instantly share code, notes, and snippets.

@brittanydionigi
Last active December 20, 2015 09:09
Show Gist options
  • Save brittanydionigi/6105325 to your computer and use it in GitHub Desktop.
Save brittanydionigi/6105325 to your computer and use it in GitHub Desktop.
git aliases
# forked from: https://github.com/hashrocket/dotmatrix/blob/master/.hashrc
# git_prompt_info accepts 0 or 1 arguments (i.e., format string)
# returns text to add to bash PS1 prompt (includes branch name)
git_prompt_info () {
local g="$(git rev-parse --git-dir 2>/dev/null)"
if [ -n "$g" ]; then
local r
local b
local d
local s
# Rebasing
if [ -d "$g/rebase-apply" ] ; then
if test -f "$g/rebase-apply/rebasing" ; then
r="|REBASE"
fi
b="$(git symbolic-ref HEAD 2>/dev/null)"
# Interactive rebase
elif [ -f "$g/rebase-merge/interactive" ] ; then
r="|REBASE-i"
b="$(cat "$g/rebase-merge/head-name")"
# Merging
elif [ -f "$g/MERGE_HEAD" ] ; then
r="|MERGING"
b="$(git symbolic-ref HEAD 2>/dev/null)"
else
if [ -f "$g/BISECT_LOG" ] ; then
r="|BISECTING"
fi
if ! b="$(git symbolic-ref HEAD 2>/dev/null)" ; then
if ! b="$(git describe --exact-match HEAD 2>/dev/null)" ; then
b="$(cut -c1-7 "$g/HEAD")..."
fi
fi
fi
# Dirty Branch
local newfile='?? '
if [ -n "$ZSH_VERSION" ]; then
newfile='\?\? '
fi
d=''
s=$(git status --porcelain 2> /dev/null)
[[ $s =~ "$newfile" ]] && d+='+'
[[ $s =~ "M " ]] && d+='*'
[[ $s =~ "D " ]] && d+='-'
printf "${1-"(%s) "}" "${b##refs/heads/}$r$d"
fi
}
gco () {
if [[ $1 == '.' ]]; then
git add -A
git commit -m "CHECKING OUT CURRENT DIRECTORY" -q
git reset HEAD^ -q
git checkout .
else
git checkout "$@"
fi
}
alias ga='git add'
alias gap='git add -p'
alias gnap='git add -N . && git add -p'
alias gb='git branch'
alias gc='git commit -v'
alias gca='git commit -a -v'
alias gd='git diff'
alias gdc='git diff --cached'
alias gdh='git diff HEAD'
alias gpull='git pull'
alias gl='git log'
alias glp='git log --oneline --decorate=no'
alias gln="git ln | perl -ple 's/\*/sprintf(\"%2s\", \$n++)/e' | less"
alias gpush='git push'
alias gpr='git pull --rebase'
alias gst='git status'
alias gr='git rebase'
alias gprc='git rebase --continue'
alias gpra='git rebase --abort'
alias gcb='gco -b'
alias gcp='git cherry-pick'
alias gcs='git stash save'
alias gsl='git stash list'
alias gsp='git stash pop'
alias gsa='git stash apply'
alias reset-authors='git commit --amend --reset-author -C HEAD'
alias vi='vim'
[ -z "$PS1" ] || stty -ixon
[ -z "$PS1" ] || export PS1="\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;36m\]\w\[\033[00m\]\$(git_prompt_info '(%s)')$ "
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment