Skip to content

Instantly share code, notes, and snippets.

@mapsi
Last active January 31, 2026 08:59
Show Gist options
  • Select an option

  • Save mapsi/64cd77a0674a9d7a2036921465a2eff6 to your computer and use it in GitHub Desktop.

Select an option

Save mapsi/64cd77a0674a9d7a2036921465a2eff6 to your computer and use it in GitHub Desktop.
Fish shell git abbreviations and functions from oh-my-zsh – complete with descriptions
# Git abbreviations converted from oh-my-zsh git plugin
# Add this to ~/.config/fish/conf.d/abbreviations.fish or similar
# Helper functions
function git_main_branch --description 'Get the default main branch name'
command git rev-parse --git-dir &>/dev/null; or return
set -l branches main trunk mainline default stable master
for branch in $branches
for location in refs/heads refs/remotes/origin refs/remotes/upstream
set -l ref $location/$branch
if command git show-ref -q --verify $ref
echo $branch
return 0
end
end
end
# Fallback: try to get the default branch from remote HEAD symbolic refs
for remote in origin upstream
set -l ref (command git rev-parse --abbrev-ref $remote/HEAD 2>/dev/null)
if string match -q "$remote/*" $ref
echo (string replace "$remote/" "" $ref)
return 0
end
end
# If no main branch was found, fall back to master but return error
echo master
return 1
end
function git_develop_branch --description 'Get the default develop branch name'
command git rev-parse --git-dir &>/dev/null; or return
for branch in dev devel develop development
if command git show-ref -q --verify refs/heads/$branch
echo $branch
return 0
end
end
echo develop
return 1
end
function git_current_branch --description 'Get the current branch name'
set -l ref (command git symbolic-ref --quiet --short HEAD 2>/dev/null)
and echo $ref
or echo (command git rev-parse --short HEAD 2>/dev/null)
end
function grename --description 'Rename a branch locally and on origin'
if test -z "$argv[1]" -o -z "$argv[2]"
echo "Usage: $0 old_branch new_branch"
return 1
end
# Rename branch locally
git branch -m "$argv[1]" "$argv[2]"
# Rename branch in origin remote
if git push origin :"$argv[1]"
git push --set-upstream origin "$argv[2]"
end
end
function gunwipall --description 'Remove all WIP commits'
set -l _commit (git log --grep='--wip--' --invert-grep --max-count=1 --format=format:%H)
# Check if a commit without "--wip--" was found and it's not the same as HEAD
if test "$_commit" != (git rev-parse HEAD)
git reset $_commit; or return 1
end
end
function work_in_progress --description 'Check if current branch is WIP'
command git -c log.showSignature=false log -n 1 2>/dev/null | grep -q -- "--wip--" && echo "WIP!!"
end
function ggpnp --description 'Pull then push current branch'
if test (count $argv) -eq 0
ggl && ggp
else
ggl $argv && ggp $argv
end
end
function gbda --description 'Delete all merged branches'
set -l main (git_main_branch)
set -l develop (git_develop_branch)
git branch --no-color --merged | \
command grep -vE "^([+*]|\\s*($main|$develop)\\s*\$)" | \
command xargs git branch --delete 2>/dev/null
end
function gbds --description 'Delete all squashed branches'
set -l default_branch (git_main_branch)
test $status -ne 0; and set default_branch (git_develop_branch)
git for-each-ref refs/heads/ "--format=%(refname:short)" | \
while read branch
set -l merge_base (git merge-base $default_branch $branch)
if test (git cherry $default_branch (git commit-tree (git rev-parse $branch^{tree}) -p $merge_base -m _) | string match '*' -) = '-'
git branch -D $branch
end
end
end
function gdv --description 'Show git diff in view'
git diff -w $argv | view -
end
function gdnolock --description 'Show git diff excluding lock files'
git diff $argv ":(exclude)package-lock.json" ":(exclude)*.lock"
end
function gccd --description 'Clone repo and cd into it'
# Get repo URI from args - simplified version for fish
set -l repo $argv[-1]
# Clone repository and exit if it fails
command git clone --recurse-submodules $argv; or return
# If last arg was a directory, that's where the repo was cloned
# Otherwise parse the repo URI and use the last part as the directory
if test -d $repo
cd $repo
else
set -l dirname (string replace -r '\.git/?$' '' (basename $repo))
cd $dirname
end
end
function _git_log_prettily --description 'Show git log with custom format'
if test -n "$argv[1]"
git log --pretty=$argv[1]
end
end
function ggu --description 'Pull current branch with rebase from origin'
set -l b (git_current_branch)
if test (count $argv) -ne 1
set b (git_current_branch)
else
set b $argv[1]
end
git pull --rebase origin $b
end
function ggl --description 'Pull current branch from origin'
if test (count $argv) -gt 1
git pull origin $argv
else
set -l b (git_current_branch)
if test (count $argv) -eq 0
set b (git_current_branch)
else
set b $argv[1]
end
git pull origin $b
end
end
function ggf --description 'Force push current branch to origin'
set -l b (git_current_branch)
if test (count $argv) -ne 1
set b (git_current_branch)
else
set b $argv[1]
end
git push --force origin $b
end
function ggfl --description 'Force push with lease current branch to origin'
set -l b (git_current_branch)
if test (count $argv) -ne 1
set b (git_current_branch)
else
set b $argv[1]
end
git push --force-with-lease origin $b
end
function ggp --description 'Push current branch to origin'
if test (count $argv) -gt 1
git push origin $argv
else
set -l b (git_current_branch)
if test (count $argv) -eq 0
set b (git_current_branch)
else
set b $argv[1]
end
git push origin $b
end
end
# Basic git commands
abbr -a g git
abbr -a ga 'git add'
abbr -a gaa 'git add --all'
abbr -a gapa 'git add --patch'
abbr -a gau 'git add --update'
abbr -a gav 'git add --verbose'
abbr -a gwip 'git add -A; git rm (git ls-files --deleted) 2> /dev/null; git commit --no-verify --no-gpg-sign --message "--wip-- [skip ci]"'
# Git am (apply mailbox)
abbr -a gam 'git am'
abbr -a gama 'git am --abort'
abbr -a gamc 'git am --continue'
abbr -a gamscp 'git am --show-current-patch'
abbr -a gams 'git am --skip'
# Git apply
abbr -a gap 'git apply'
abbr -a gapt 'git apply --3way'
# Git bisect
abbr -a gbs 'git bisect'
abbr -a gbsb 'git bisect bad'
abbr -a gbsg 'git bisect good'
abbr -a gbsn 'git bisect new'
abbr -a gbso 'git bisect old'
abbr -a gbsr 'git bisect reset'
abbr -a gbss 'git bisect start'
# Git blame
abbr -a gbl 'git blame -w'
# Git branch
abbr -a gb 'git branch'
abbr -a gba 'git branch --all'
abbr -a gbd 'git branch --delete'
abbr -a gbD 'git branch --delete --force'
abbr -a gbm 'git branch --move'
abbr -a gbnm 'git branch --no-merged'
abbr -a gbr 'git branch --remote'
abbr -a gbgd 'LANG=C git branch --no-color -vv | grep ": gone]" | cut -c 3- | awk '"'"'{print $1}'"'"' | xargs git branch -d'
abbr -a gbgD 'LANG=C git branch --no-color -vv | grep ": gone]" | cut -c 3- | awk '"'"'{print $1}'"'"' | xargs git branch -D'
abbr -a gbg 'LANG=C git branch -vv | grep ": gone]"'
abbr -a ggsup 'git branch --set-upstream-to=origin/(git_current_branch)'
# Git checkout
abbr -a gco 'git checkout'
abbr -a gcor 'git checkout --recurse-submodules'
abbr -a gcb 'git checkout -b'
abbr -a gcB 'git checkout -B'
abbr -a gcd 'git checkout (git_develop_branch)'
abbr -a gcm 'git checkout (git_main_branch)'
# Git cherry-pick
abbr -a gcp 'git cherry-pick'
abbr -a gcpa 'git cherry-pick --abort'
abbr -a gcpc 'git cherry-pick --continue'
# Git clean
abbr -a gclean 'git clean --interactive -d'
# Git clone
abbr -a gcl 'git clone --recurse-submodules'
abbr -a gclf 'git clone --recursive --shallow-submodules --filter=blob:none --also-filter-submodules'
# Git commit
abbr -a gcam 'git commit --all --message'
abbr -a gcas 'git commit --all --signoff'
abbr -a gcasm 'git commit --all --signoff --message'
abbr -a gcs 'git commit --gpg-sign'
abbr -a gcss 'git commit --gpg-sign --signoff'
abbr -a gcssm 'git commit --gpg-sign --signoff --message'
abbr -a gcmsg 'git commit --message'
abbr -a gcsm 'git commit --signoff --message'
abbr -a gc 'git commit --verbose'
abbr -a gca 'git commit --verbose --all'
abbr -a 'gca!' 'git commit --verbose --all --amend'
abbr -a 'gcan!' 'git commit --verbose --all --no-edit --amend'
abbr -a 'gcans!' 'git commit --verbose --all --signoff --no-edit --amend'
abbr -a 'gcann!' 'git commit --verbose --all --date=now --no-edit --amend'
abbr -a 'gc!' 'git commit --verbose --amend'
abbr -a gcn 'git commit --verbose --no-edit'
abbr -a 'gcn!' 'git commit --verbose --no-edit --amend'
abbr -a gcf 'git config --list'
abbr -a gcfu 'git commit --fixup'
# Git describe/diff
abbr -a gdct 'git describe --tags (git rev-list --tags --max-count=1)'
abbr -a gd 'git diff'
abbr -a gdca 'git diff --cached'
abbr -a gdcw 'git diff --cached --word-diff'
abbr -a gds 'git diff --staged'
abbr -a gdw 'git diff --word-diff'
abbr -a gdup 'git diff @{upstream}'
abbr -a gdt 'git diff-tree --no-commit-id --name-only -r'
# Git fetch
abbr -a gf 'git fetch'
abbr -a gfa 'git fetch --all --tags --prune --jobs=10'
abbr -a gfo 'git fetch origin'
# Git gui
abbr -a gg 'git gui citool'
abbr -a gga 'git gui citool --amend'
# Git help
abbr -a ghh 'git help'
# Git log
abbr -a glgg 'git log --graph'
abbr -a glgga 'git log --graph --decorate --all'
abbr -a glgm 'git log --graph --max-count=10'
abbr -a glods 'git log --graph --pretty="%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%ad) %C(bold blue)<%an>%Creset" --date=short'
abbr -a glod 'git log --graph --pretty="%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%ad) %C(bold blue)<%an>%Creset"'
abbr -a glola 'git log --graph --pretty="%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%ar) %C(bold blue)<%an>%Creset" --all'
abbr -a glols 'git log --graph --pretty="%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%ar) %C(bold blue)<%an>%Creset" --stat'
abbr -a glol 'git log --graph --pretty="%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%ar) %C(bold blue)<%an>%Creset"'
abbr -a glo 'git log --oneline --decorate'
abbr -a glog 'git log --oneline --decorate --graph'
abbr -a gloga 'git log --oneline --decorate --graph --all'
abbr -a glp '_git_log_prettily'
abbr -a glg 'git log --stat'
abbr -a glgp 'git log --stat --patch'
# Git ls-files
abbr -a gignored 'git ls-files -v | grep "^[[:lower:]]"'
abbr -a gfg 'git ls-files | grep'
# Git merge
abbr -a gm 'git merge'
abbr -a gma 'git merge --abort'
abbr -a gmc 'git merge --continue'
abbr -a gms 'git merge --squash'
abbr -a gmff 'git merge --ff-only'
abbr -a gmom 'git merge origin/(git_main_branch)'
abbr -a gmum 'git merge upstream/(git_main_branch)'
abbr -a gmtl 'git merge --no-prompt'
abbr -a gmtlvim 'git mergetool --no-prompt --tool=vimdiff'
# Git pull
abbr -a gl 'git pull'
abbr -a gpr 'git pull --rebase'
abbr -a gprv 'git pull --rebase -v'
abbr -a gpra 'git pull --rebase --autostash'
abbr -a gprav 'git pull --rebase --autostash -v'
abbr -a gprom 'git pull --rebase origin (git_main_branch)'
abbr -a gpromi 'git pull --rebase=interactive origin (git_main_branch)'
abbr -a gprum 'git pull --rebase upstream (git_main_branch)'
abbr -a gprumi 'git pull --rebase=interactive upstream (git_main_branch)'
abbr -a ggpull 'git pull origin "(git_current_branch)"'
abbr -a gluc 'git pull upstream (git_current_branch)'
abbr -a glum 'git pull upstream (git_main_branch)'
# Git push
abbr -a gp 'git push'
abbr -a gpd 'git push --dry-run'
abbr -a 'gpf!' 'git push --force'
abbr -a gpf 'git push --force-with-lease'
abbr -a gpv 'git push --verbose'
abbr -a gpoat 'git push origin --all && git push origin --tags'
abbr -a gpod 'git push origin --delete'
abbr -a gpu 'git push upstream'
abbr -a gpsup 'git push --set-upstream origin (git_current_branch)'
abbr -a gpsupf 'git push --set-upstream origin (git_current_branch) --force-with-lease'
abbr -a ggpush 'git push origin "(git_current_branch)"'
# Git rebase
abbr -a grb 'git rebase'
abbr -a grba 'git rebase --abort'
abbr -a grbc 'git rebase --continue'
abbr -a grbi 'git rebase --interactive'
abbr -a grbo 'git rebase --onto'
abbr -a grbs 'git rebase --skip'
abbr -a grbd 'git rebase (git_develop_branch)'
abbr -a grbm 'git rebase (git_main_branch)'
abbr -a grbom 'git rebase origin/(git_main_branch)'
abbr -a grbum 'git rebase upstream/(git_main_branch)'
# Git reflog
abbr -a grf 'git reflog'
# Git remote
abbr -a gr 'git remote'
abbr -a grv 'git remote --verbose'
abbr -a gra 'git remote add'
abbr -a grrm 'git remote remove'
abbr -a grmv 'git remote rename'
abbr -a grset 'git remote set-url'
abbr -a grup 'git remote update'
# Git reset
abbr -a grh 'git reset'
abbr -a gru 'git reset --'
abbr -a grhh 'git reset --hard'
abbr -a grhk 'git reset --keep'
abbr -a grhs 'git reset --soft'
abbr -a gpristine 'git reset --hard && git clean --force -dfx'
abbr -a gwipe 'git reset --hard && git clean --force -df'
abbr -a groh 'git reset origin/(git_current_branch) --hard'
abbr -a gunwip 'git rev-list --max-count=1 --format="%s" HEAD | grep -q "\--wip--" && git reset HEAD~1'
# Git restore
abbr -a grs 'git restore'
abbr -a grss 'git restore --source'
abbr -a grst 'git restore --staged'
# Git revert
abbr -a grev 'git revert'
abbr -a greva 'git revert --abort'
abbr -a grevc 'git revert --continue'
# Git rm
abbr -a grm 'git rm'
abbr -a grmc 'git rm --cached'
# Git show
abbr -a gsh 'git show'
abbr -a gsps 'git show --pretty=short --show-signature'
# Git shortlog
abbr -a gcount 'git shortlog --summary --numbered'
# Git stash
abbr -a gstall 'git stash --all'
abbr -a gstaa 'git stash apply'
abbr -a gstc 'git stash clear'
abbr -a gstd 'git stash drop'
abbr -a gstl 'git stash list'
abbr -a gstp 'git stash pop'
abbr -a gsta 'git stash push'
abbr -a gsts 'git stash show --patch'
abbr -a gstu 'gsta --include-untracked'
# Git status
abbr -a gst 'git status'
abbr -a gss 'git status --short'
abbr -a gsb 'git status --short --branch'
# Git submodule
abbr -a gsi 'git submodule init'
abbr -a gsu 'git submodule update'
# Git svn
abbr -a gsd 'git svn dcommit'
abbr -a gsr 'git svn rebase'
# Git switch
abbr -a gsw 'git switch'
abbr -a gswc 'git switch --create'
abbr -a gswd 'git switch (git_develop_branch)'
abbr -a gswm 'git switch (git_main_branch)'
# Git tag
abbr -a gta 'git tag --annotate'
abbr -a gts 'git tag --sign'
abbr -a gtv 'git tag | sort -V'
# Git update-index
abbr -a gignore 'git update-index --assume-unchanged'
abbr -a gunignore 'git update-index --no-assume-unchanged'
# Git worktree
abbr -a gwt 'git worktree'
abbr -a gwta 'git worktree add'
abbr -a gwtls 'git worktree list'
abbr -a gwtmv 'git worktree move'
abbr -a gwtrm 'git worktree remove'
# Miscellaneous
abbr -a gwch 'git log --patch --abbrev-commit --pretty=medium --raw'
abbr -a grt 'cd (git rev-parse --show-toplevel || echo .)'
abbr -a gk 'gitk --all --branches &!'
abbr -a gke 'gitk --all (git log --walk-reflogs --pretty=%h) &!'
abbr -a gtl 'git tag --sort=-v:refname -n --list'
abbr -a git-svn-dcommit-push 'git svn dcommit && git push github (git_main_branch):svntrunk'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment