Skip to content

Instantly share code, notes, and snippets.

@bittner
Forked from chrisberkhout/.bash_profile
Last active March 14, 2024 13:18
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bittner/22ad4c5c71967f7a5ec7a6e5fc8c098d to your computer and use it in GitHub Desktop.
Save bittner/22ad4c5c71967f7a5ec7a6e5fc8c098d to your computer and use it in GitHub Desktop.
Git aliases taken from oh-my-zsh's git plugin and translated to bash (plus a few more aliases)
# git aliases - taken from oh-my-zsh's git plugin and translated to bash
# https://github.com/robbyrussell/oh-my-zsh/wiki/Cheatsheet#helpful-aliases-for-common-git-tasks
# https://github.com/robbyrussell/oh-my-zsh/blob/master/plugins/git/git.plugin.zsh
function git_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 git_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)
}
alias g="git"
alias gb="git branch"
alias gba="git branch -a"
alias gbd="git branch -d"
alias gbD="git branch -D"
alias gbr="git branch -r"
alias gcount="git shortlog -sn"
alias gcl="git config --list"
alias gcp="git cherry-pick"
alias gs="git status"
alias gsh="git show"
alias gst="git status"
alias gl="git pull"
alias gup="git pull --rebase"
alias gp="git push"
alias gpf="git push -f"
alias gpu="git push -u"
alias gd="git diff"
alias gdw="git diff -w"
alias gdc="git diff --cached"
alias gdcw="git diff --cached -w"
alias gds="git diff --staged"
alias gdsw="git diff --staged -w"
function gdv() { # mine doesn't add -w
git diff $@ | vim -R -
}
function gdcv() { # my own
git diff --cached $@ | vim -R -
}
alias gc="git commit -v"
alias gc!="git commit -v --amend"
alias gca="git commit -v -a"
alias gca!="git commit -v -a --amend"
alias gcn!="git commit -v --amend --no-edit"
alias gcm="git commit -m"
alias gcmsg="git commit -m"
alias gco="git checkout"
alias gcob="git checkout -b"
alias gr="git remote"
alias grm="git rm"
alias grv="git remote -v"
alias grmv="git remote rename"
alias grrm="git remote remove"
alias gsetr="git remote set-url"
alias grup="git remote update"
alias grb="git rebase"
alias grba="git rebase --abort"
alias grbc="git rebase --continue"
alias grbi="git rebase -i"
alias glg="git log --stat --max-count=10"
alias glgg="git log --graph --max-count=10"
alias glgga="git log --graph --decorate --all"
alias glo="git log --oneline --decorate --color"
alias glog="git log --oneline --decorate --color --graph"
alias gss="git status -s"
alias ga="git add"
alias gav="git add -v"
alias gm="git merge"
alias gmv="git mv"
alias grh="git reset HEAD"
alias grhh="git reset HEAD --hard"
alias gclean="git reset --hard && git clean -dfx"
alias gwc="git whatchanged -p --abbrev-commit --pretty=medium"
alias gsta="git stash"
alias gstd="git stash drop"
alias gstp="git stash pop"
alias gsts="git stash show --text"
alias gt="git tag"
alias gtd="git tag -d"
function ggpull {
git pull origin $(git_current_branch)
}
function ggpur {
git pull --rebase origin $(git_current_branch)
}
function ggpush {
git push origin $(git_current_branch)
}
function ggpnp {
git pull origin $(git_current_branch) && git push origin $(git_current_branch)
}
function glp() {
git log --pretty=$@
}
@bittner
Copy link
Author

bittner commented Mar 11, 2022

Alternatives

git config --global alias.unstage 'reset HEAD --'
git config --global alias.undo 'reset HEAD~1 --soft'
git unstage
git undo

'Enjoy the power of Oh My Zsh Git shortcuts and Git aliases for unstage and undo!'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment