Skip to content

Instantly share code, notes, and snippets.

@jimmyhchan
Last active July 2, 2021 17:30
Show Gist options
  • Save jimmyhchan/1745074c42e75189eacbc21f8b333dfd to your computer and use it in GitHub Desktop.
Save jimmyhchan/1745074c42e75189eacbc21f8b333dfd to your computer and use it in GitHub Desktop.
aliases for git
# HEY DO THIS
# ... add this to your .bash_profile
# if [ -f ~/.bashrc ]; then
# source ~/.bashrc
# fi
# bash completion
if [ -f /usr/local/etc/bash_completion ]; then
. /usr/local/etc/bash_completion
fi
[ -d /usr/local/etc/bash_completion.d ] && . /usr/local/etc/bash_completion.d/*
export EDITOR="vim"
alias gb='git branch -v'
alias gs='git status'
alias gd='git diff'
alias gl='git log'
alias gdd='git diff --cached'
alias ga.='git add .'
alias gpr='git pull --rebase'
alias grc='git rebase --continue'
# gc => git checkout main
# gc bugs => git checkout bugs
function gc {
# remoteHead=`git symbolic-ref refs/remotes/origin/HEAD | sed 's@^refs/remotes/origin/@@'`
remoteHead=`git remote show origin | awk '/HEAD branch/ {print $NF}'`
if [ -z "$1" ]; then
git checkout $remoteHead
else
git checkout $1
fi
}
__git_complete gc _git_checkout
function gcob {
if [ "$1" ]; then
#remoteHead=`git symbolic-ref refs/remotes/origin/HEAD | sed 's@^refs/remotes/origin/@@'`
remoteHead=`git remote show origin | awk '/HEAD branch/ {print $NF}'`
git checkout -b $1 ${2:-$remoteHead}
fi
}
__git_complete gcob _git_checkout
function gri {
remoteHead=`git symbolic-ref refs/remotes/origin/HEAD | sed 's@^refs/remotes/origin/@@'`
git rebase -i ${1:-$remoteHead}
}
alias gitdiff='git diff --color-words'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment