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'
git branch --no-color --merged | \
command grep -vE "^([+*]|\s*($(git_main_branch)|$(git_develop_branch))\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 --add g git --description 'Git'
abbr --add ga 'git add' --description 'Stage files'
abbr --add gaa 'git add --all' --description 'Stage all changes'
abbr --add gapa 'git add --patch' --description 'Stage changes interactively'
abbr --add gau 'git add --update' --description 'Stage modified and deleted files'
abbr --add gav 'git add --verbose' --description 'Stage files verbosely'
abbr --add gwip 'git add -A; git rm (git ls-files --deleted) 2> /dev/null; git commit --no-verify --no-gpg-sign --message "--wip-- [skip ci]"' --description 'Create a WIP commit'
# Git am (apply mailbox)
abbr --add gam 'git am' --description 'Apply patches from mailbox'
abbr --add gama 'git am --abort' --description 'Abort am operation'
abbr --add gamc 'git am --continue' --description 'Continue am operation'
abbr --add gamscp 'git am --show-current-patch' --description 'Show current patch'
abbr --add gams 'git am --skip' --description 'Skip current patch'
# Git apply
abbr --add gap 'git apply' --description 'Apply a patch'
abbr --add gapt 'git apply --3way' --description 'Apply patch with 3-way merge'
# Git bisect
abbr --add gbs 'git bisect' --description 'Bisect to find problematic commit'
abbr --add gbsb 'git bisect bad' --description 'Mark commit as bad'
abbr --add gbsg 'git bisect good' --description 'Mark commit as good'
abbr --add gbsn 'git bisect new' --description 'Mark commit as new'
abbr --add gbso 'git bisect old' --description 'Mark commit as old'
abbr --add gbsr 'git bisect reset' --description 'Reset bisect'
abbr --add gbss 'git bisect start' --description 'Start bisect'
# Git blame
abbr --add gbl 'git blame -w' --description 'Show who changed each line (ignore whitespace)'
# Git branch
abbr --add gb 'git branch' --description 'List branches'
abbr --add gba 'git branch --all' --description 'List all branches'
abbr --add gbd 'git branch --delete' --description 'Delete branch'
abbr --add gbD 'git branch --delete --force' --description 'Force delete branch'
abbr --add gbm 'git branch --move' --description 'Rename branch'
abbr --add gbnm 'git branch --no-merged' --description 'List unmerged branches'
abbr --add gbr 'git branch --remote' --description 'List remote branches'
abbr --add gbgd "LANG=C git branch --no-color -vv | grep \": gone]\" | cut -c 3- | awk '{print \$1}' | xargs git branch -d" --description 'Delete branches marked as gone'
abbr --add gbgD "LANG=C git branch --no-color -vv | grep \": gone]\" | cut -c 3- | awk '{print \$1}' | xargs git branch -D" --description 'Force delete branches marked as gone'
abbr --add gbg 'LANG=C git branch -vv | grep ": gone]"' --description 'Show branches marked as gone'
abbr --add ggsup 'git branch --set-upstream-to=origin/(git_current_branch)' --description 'Set upstream for current branch'
# Git checkout
abbr --add gco 'git checkout' --description 'Checkout branch or files'
abbr --add gcor 'git checkout --recurse-submodules' --description 'Checkout with submodules'
abbr --add gcb 'git checkout -b' --description 'Create and checkout branch'
abbr --add gcB 'git checkout -B' --description 'Force create and checkout branch'
abbr --add gcd 'git checkout (git_develop_branch)' --description 'Checkout develop branch'
abbr --add gcm 'git checkout (git_main_branch)' --description 'Checkout main branch'
# Git cherry-pick
abbr --add gcp 'git cherry-pick' --description 'Apply commit to current branch'
abbr --add gcpa 'git cherry-pick --abort' --description 'Abort cherry-pick'
abbr --add gcpc 'git cherry-pick --continue' --description 'Continue cherry-pick'
# Git clean
abbr --add gclean 'git clean --interactive -d' --description 'Clean untracked files interactively'
# Git clone
abbr --add gcl 'git clone --recurse-submodules' --description 'Clone repo with submodules'
abbr --add gclf 'git clone --recursive --shallow-submodules --filter=blob:none --also-filter-submodules' --description 'Clone with partial blob filter'
# Git commit
abbr --add gcam 'git commit --all --message' --description 'Commit all changes with message'
abbr --add gcas 'git commit --all --signoff' --description 'Commit all with signoff'
abbr --add gcasm 'git commit --all --signoff --message' --description 'Commit all with signoff and message'
abbr --add gcs 'git commit --gpg-sign' --description 'GPG sign commit'
abbr --add gcss 'git commit --gpg-sign --signoff' --description 'GPG sign and signoff'
abbr --add gcssm 'git commit --gpg-sign --signoff --message' --description 'GPG sign, signoff, and message'
abbr --add gcmsg 'git commit --message' --description 'Commit with message'
abbr --add gcsm 'git commit --signoff --message' --description 'Commit with signoff and message'
abbr --add gc 'git commit --verbose' --description 'Commit verbosely'
abbr --add gca 'git commit --verbose --all' --description 'Commit all changes verbosely'
abbr --add 'gca!' 'git commit --verbose --all --amend' --description 'Amend all changes verbosely'
abbr --add 'gcan!' 'git commit --verbose --all --no-edit --amend' --description 'Amend all without editing'
abbr --add 'gcans!' 'git commit --verbose --all --signoff --no-edit --amend' --description 'Amend all with signoff, no edit'
abbr --add 'gcann!' 'git commit --verbose --all --date=now --no-edit --amend' --description 'Amend with new date, no edit'
abbr --add 'gc!' 'git commit --verbose --amend' --description 'Amend commit verbosely'
abbr --add gcn 'git commit --verbose --no-edit' --description 'Commit without editing message'
abbr --add 'gcn!' 'git commit --verbose --no-edit --amend' --description 'Amend without editing message'
abbr --add gcf 'git config --list' --description 'List git config'
abbr --add gcfu 'git commit --fixup' --description 'Commit as fixup'
# Git describe/diff
abbr --add gdct 'git describe --tags (git rev-list --tags --max-count=1)' --description 'Show latest tag'
abbr --add gd 'git diff' --description 'Show changes'
abbr --add gdca 'git diff --cached' --description 'Show staged changes'
abbr --add gdcw 'git diff --cached --word-diff' --description 'Show staged changes by word'
abbr --add gds 'git diff --staged' --description 'Show staged changes'
abbr --add gdw 'git diff --word-diff' --description 'Show changes by word'
abbr --add gdup 'git diff @{upstream}' --description 'Show changes vs upstream'
abbr --add gdt 'git diff-tree --no-commit-id --name-only -r' --description 'Show files changed in commit'
# Git fetch
abbr --add gf 'git fetch' --description 'Fetch from remote'
abbr --add gfa 'git fetch --all --tags --prune --jobs=10' --description 'Fetch all with tags and pruning'
abbr --add gfo 'git fetch origin' --description 'Fetch from origin'
# Git gui
abbr --add gg 'git gui citool' --description 'Open git GUI'
abbr --add gga 'git gui citool --amend' --description 'Open git GUI to amend'
# Git help
abbr --add ghh 'git help' --description 'Show git help'
# Git log
abbr --add glgg 'git log --graph' --description 'Log with graph'
abbr --add glgga 'git log --graph --decorate --all' --description 'Log with graph, all branches'
abbr --add glgm 'git log --graph --max-count=10' --description 'Log graph (last 10)'
abbr --add glods 'git log --graph --pretty="%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%ad) %C(bold blue)<%an>%Creset" --date=short' --description 'Log with short date'
abbr --add glod 'git log --graph --pretty="%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%ad) %C(bold blue)<%an>%Creset"' --description 'Log with full date'
abbr --add glola 'git log --graph --pretty="%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%ar) %C(bold blue)<%an>%Creset" --all' --description 'Log with relative date, all'
abbr --add glols 'git log --graph --pretty="%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%ar) %C(bold blue)<%an>%Creset" --stat' --description 'Log with stats'
abbr --add glol 'git log --graph --pretty="%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%ar) %C(bold blue)<%an>%Creset"' --description 'Log with relative date'
abbr --add glo 'git log --oneline --decorate' --description 'Log oneline'
abbr --add glog 'git log --oneline --decorate --graph' --description 'Log oneline with graph'
abbr --add gloga 'git log --oneline --decorate --graph --all' --description 'Log oneline with graph, all'
abbr --add glp '_git_log_prettily' --description 'Log with custom format'
abbr --add glg 'git log --stat' --description 'Log with stats'
abbr --add glgp 'git log --stat --patch' --description 'Log with stats and patches'
# Git ls-files
abbr --add gignored 'git ls-files -v | grep "^[[:lower:]]"' --description 'Show ignored files'
abbr --add gfg 'git ls-files | grep' --description 'Grep tracked files'
# Git merge
abbr --add gm 'git merge' --description 'Merge branch'
abbr --add gma 'git merge --abort' --description 'Abort merge'
abbr --add gmc 'git merge --continue' --description 'Continue merge'
abbr --add gms 'git merge --squash' --description 'Merge with squash'
abbr --add gmff 'git merge --ff-only' --description 'Merge fast-forward only'
abbr --add gmom 'git merge origin/(git_main_branch)' --description 'Merge origin main'
abbr --add gmum 'git merge upstream/(git_main_branch)' --description 'Merge upstream main'
abbr --add gmtl 'git merge --no-prompt' --description 'Merge with default tool'
abbr --add gmtlvim 'git mergetool --no-prompt --tool=vimdiff' --description 'Merge with vimdiff'
# Git pull
abbr --add gl 'git pull' --description 'Pull from remote'
abbr --add gpr 'git pull --rebase' --description 'Pull with rebase'
abbr --add gprv 'git pull --rebase -v' --description 'Pull with rebase (verbose)'
abbr --add gpra 'git pull --rebase --autostash' --description 'Pull with rebase and autostash'
abbr --add gprav 'git pull --rebase --autostash -v' --description 'Pull with rebase, autostash, verbose'
abbr --add gprom 'git pull --rebase origin (git_main_branch)' --description 'Pull main with rebase'
abbr --add gpromi 'git pull --rebase=interactive origin (git_main_branch)' --description 'Pull main with interactive rebase'
abbr --add gprum 'git pull --rebase upstream (git_main_branch)' --description 'Pull upstream main with rebase'
abbr --add gprumi 'git pull --rebase=interactive upstream (git_main_branch)' --description 'Pull upstream main, interactive rebase'
abbr --add ggpull 'git pull origin "(git_current_branch)"' --description 'Pull current branch'
abbr --add gluc 'git pull upstream (git_current_branch)' --description 'Pull current from upstream'
abbr --add glum 'git pull upstream (git_main_branch)' --description 'Pull main from upstream'
# Git push
abbr --add gp 'git push' --description 'Push to remote'
abbr --add gpd 'git push --dry-run' --description 'Dry run push'
abbr --add 'gpf!' 'git push --force' --description 'Force push'
abbr --add gpf 'git push --force-with-lease' --description 'Force push with lease'
abbr --add gpv 'git push --verbose' --description 'Push verbosely'
abbr --add gpoat 'git push origin --all && git push origin --tags' --description 'Push all branches and tags'
abbr --add gpod 'git push origin --delete' --description 'Delete on origin'
abbr --add gpu 'git push upstream' --description 'Push to upstream'
abbr --add gpsup 'git push --set-upstream origin (git_current_branch)' --description 'Push and set upstream'
abbr --add gpsupf 'git push --set-upstream origin (git_current_branch) --force-with-lease' --description 'Force push and set upstream'
abbr --add ggpush 'git push origin "(git_current_branch)"' --description 'Push current branch'
# Git rebase
abbr --add grb 'git rebase' --description 'Rebase branch'
abbr --add grba 'git rebase --abort' --description 'Abort rebase'
abbr --add grbc 'git rebase --continue' --description 'Continue rebase'
abbr --add grbi 'git rebase --interactive' --description 'Interactive rebase'
abbr --add grbo 'git rebase --onto' --description 'Rebase onto branch'
abbr --add grbs 'git rebase --skip' --description 'Skip commit in rebase'
abbr --add grbd 'git rebase (git_develop_branch)' --description 'Rebase onto develop'
abbr --add grbm 'git rebase (git_main_branch)' --description 'Rebase onto main'
abbr --add grbom 'git rebase origin/(git_main_branch)' --description 'Rebase onto origin main'
abbr --add grbum 'git rebase upstream/(git_main_branch)' --description 'Rebase onto upstream main'
# Git reflog
abbr --add grf 'git reflog' --description 'Show reflog'
# Git remote
abbr --add gr 'git remote' --description 'Manage remotes'
abbr --add grv 'git remote --verbose' --description 'List remotes with URLs'
abbr --add gra 'git remote add' --description 'Add remote'
abbr --add grrm 'git remote remove' --description 'Remove remote'
abbr --add grmv 'git remote rename' --description 'Rename remote'
abbr --add grset 'git remote set-url' --description 'Set remote URL'
abbr --add grup 'git remote update' --description 'Update remotes'
# Git reset
abbr --add grh 'git reset' --description 'Reset changes'
abbr --add gru 'git reset --' --description 'Unstage files'
abbr --add grhh 'git reset --hard' --description 'Hard reset'
abbr --add grhk 'git reset --keep' --description 'Reset keeping changes'
abbr --add grhs 'git reset --soft' --description 'Soft reset'
abbr --add gpristine 'git reset --hard && git clean --force -dfx' --description 'Hard reset and clean'
abbr --add gwipe 'git reset --hard && git clean --force -df' --description 'Hard reset and clean directories'
abbr --add groh 'git reset origin/(git_current_branch) --hard' --description 'Reset to origin'
abbr --add gunwip 'git rev-list --max-count=1 --format="%s" HEAD | grep -q "\--wip--" && git reset HEAD~1' --description 'Undo WIP commit'
# Git restore
abbr --add grs 'git restore' --description 'Restore files'
abbr --add grss 'git restore --source' --description 'Restore from source'
abbr --add grst 'git restore --staged' --description 'Unstage files'
# Git revert
abbr --add grev 'git revert' --description 'Revert commit'
abbr --add greva 'git revert --abort' --description 'Abort revert'
abbr --add grevc 'git revert --continue' --description 'Continue revert'
# Git rm
abbr --add grm 'git rm' --description 'Remove files'
abbr --add grmc 'git rm --cached' --description 'Unstage files'
# Git show
abbr --add gsh 'git show' --description 'Show commit'
abbr --add gsps 'git show --pretty=short --show-signature' --description 'Show with signature'
# Git shortlog
abbr --add gcount 'git shortlog --summary --numbered' --description 'Count commits by author'
# Git stash
abbr --add gstall 'git stash --all' --description 'Stash everything'
abbr --add gstaa 'git stash apply' --description 'Apply stash'
abbr --add gstc 'git stash clear' --description 'Clear stash'
abbr --add gstd 'git stash drop' --description 'Delete stash'
abbr --add gstl 'git stash list' --description 'List stash'
abbr --add gstp 'git stash pop' --description 'Pop stash'
abbr --add gsta 'git stash push' --description 'Stash changes'
abbr --add gsts 'git stash show --patch' --description 'Show stash diff'
abbr --add gstu 'gsta --include-untracked' --description 'Stash untracked files too'
# Git status
abbr --add gst 'git status' --description 'Show status'
abbr --add gss 'git status --short' --description 'Show short status'
abbr --add gsb 'git status --short --branch' --description 'Show short status with branch'
# Git submodule
abbr --add gsi 'git submodule init' --description 'Initialize submodules'
abbr --add gsu 'git submodule update' --description 'Update submodules'
# Git svn
abbr --add gsd 'git svn dcommit' --description 'SVN commit'
abbr --add gsr 'git svn rebase' --description 'SVN rebase'
# Git switch
abbr --add gsw 'git switch' --description 'Switch branch'
abbr --add gswc 'git switch --create' --description 'Create and switch branch'
abbr --add gswd 'git switch (git_develop_branch)' --description 'Switch to develop'
abbr --add gswm 'git switch (git_main_branch)' --description 'Switch to main'
# Git tag
abbr --add gta 'git tag --annotate' --description 'Create annotated tag'
abbr --add gts 'git tag --sign' --description 'Create signed tag'
abbr --add gtv 'git tag | sort -V' --description 'List tags sorted'
# Git update-index
abbr --add gignore 'git update-index --assume-unchanged' --description 'Assume file unchanged'
abbr --add gunignore 'git update-index --no-assume-unchanged' --description 'Stop assuming file unchanged'
# Git worktree
abbr --add gwt 'git worktree' --description 'Manage worktrees'
abbr --add gwta 'git worktree add' --description 'Add worktree'
abbr --add gwtls 'git worktree list' --description 'List worktrees'
abbr --add gwtmv 'git worktree move' --description 'Move worktree'
abbr --add gwtrm 'git worktree remove' --description 'Remove worktree'
# Miscellaneous
abbr --add gwch 'git log --patch --abbrev-commit --pretty=medium --raw' --description 'Show what changed'
abbr --add grt 'cd (git rev-parse --show-toplevel || echo .)' --description 'Go to repo root'
abbr --add gk 'gitk --all --branches &!' --description 'Launch gitk'
abbr --add gke 'gitk --all (git log --walk-reflogs --pretty=%h) &!' --description 'Launch gitk with reflogs'
abbr --add gtl 'git tag --sort=-v:refname -n --list' --description 'List tags'
abbr --add git-svn-dcommit-push 'git svn dcommit && git push github (git_main_branch):svntrunk' --description 'SVN commit and push'
# Notes:
# All helper functions from the oh-my-zsh git plugin have been converted!
# Special abbreviations that use these functions:
# - gcd, gcm: switch to develop/main branches
# - gswd, gswm: switch to develop/main branches
# - grbd, grbm, grbom, grbum: rebase onto develop/main branches
# - gmom, gmum: merge origin/upstream main
# - ggsup: set upstream for current branch
# - gbg, gbgd, gbgD: find and delete branches marked as gone
# - ggpull, ggpush: push/pull current branch
# - gpsup, gpsupf: push with upstream tracking
# - gbda: delete all merged branches (except main/develop)
# - gbds: delete squashed branches
# - gccd: clone and cd into repo
# - gdv: git diff piped to view
# - gdnolock: git diff excluding lock files
# - gwip: WIP commit (use as function if you want git add -A behavior)
# - gunwip, gunwipall: revert WIP commits
# - grename: rename branch locally and on origin
# - work_in_progress: check if current branch is WIP
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment