Skip to content

Instantly share code, notes, and snippets.

@james2doyle
Last active May 1, 2026 09:32
Show Gist options
  • Select an option

  • Save james2doyle/6e8a120e31dbaa806a2f91478507314c to your computer and use it in GitHub Desktop.

Select an option

Save james2doyle/6e8a120e31dbaa806a2f91478507314c to your computer and use it in GitHub Desktop.
Git abbreviations for Fish shell
# tj git aliases
abbr -a gd "git diff -M"
abbr -a ga "git add"
abbr -a gaa "git add --all ."
abbr -a gbd "git branch -D"
abbr -a gs "git status"
abbr -a gca "git commit -a -m"
abbr -a gm "git merge --no-ff"
abbr -a gpt "git push --tags"
abbr -a gp "git push"
abbr -a grh "git reset --hard"
abbr -a gb "git branch"
abbr -a gcob "git checkout -b"
abbr -a gco "git checkout"
abbr -a gba "git branch -a"
abbr -a gcp "git cherry-pick"
abbr -a gl "git log --pretty=format:\"%Cgreen%h%Creset - %Cblue%an%Creset @ %ar : %s\""
abbr -a gl2 "git log --pretty='format:%Cgreen%h%Creset %an - %s' --graph"
abbr -a glv "git log --stat"
abbr -a gpom "git pull origin master"
abbr -a gcd 'cd "`git rev-parse --show-toplevel`"'
# my aliases
# remove files that are not under version control
abbr -a gcf "git clean -fd"
# discard changes in the working directory
abbr -a gcod "git checkout -- ."
# grab the latest upstream version
abbr -a gpum "git pull upstream master"
# delete branch from github. follow with branch name
abbr -a gpod "git push origin --delete"
# show git status without untracked files
abbr -a gsu "git status -uno"
# commit -m
abbr -a gcm "git commit -m"
abbr -a gcv "git commit --verbose"
abbr -a gc "git commit --verbose"
# diff in sublime
abbr -a gds "git diff | sublime"
# remove staged file
abbr -a grm "git reset HEAD"
# add current files, commit those file
abbr -a gacm "git add . --all; git commit --verbose"
# list the git tags by date
abbr -a gtd "git log --tags --simplify-by-decoration --pretty=\"format:%ai %d\""
# list stats for the repo
abbr -a grs "git shortlog -s -n --all --no-merges"
function repo-url -d "Open the current repo and branch on the website"
set url (git config --get remote.origin.url | sed 's/:/\//' | sed 's/git@/https:\/\//' | sed 's/\.git//')
set branch (git rev-parse --abbrev-ref HEAD)
switch $url
case "*bitbucket"
echo "$url/branch/$branch"
case "*"
echo "$url/tree/$branch"
end
end
@tapannallan

tapannallan commented Apr 17, 2020

Copy link
Copy Markdown

Thanks for this. Very helpful

@egarbi

egarbi commented Apr 23, 2021

Copy link
Copy Markdown

Thanks for this.
There is a typo/bug on this line
causing:

abbr --add: Requires at least two arguments

@james2doyle

Copy link
Copy Markdown
Author

@egarbi thanks - I've fixed it in the source code

@qianbinbin

qianbinbin commented May 1, 2026

Copy link
Copy Markdown

That's inspiring, thanks. I modified the repo-url to gu, so it can handle non-git directories and https repos, and open in browser on macOS:

function gu -d "Open the URL of current repo and branch"
    set url (git remote get-url origin); or return 1
    if string match -rq '^git@' $url
        set url (string replace -r '^git@(.*):' 'https://$1/' $url)
    end
    set url (string replace -r '\.git$' '' $url)

    set branch (git branch --show-current)
    test -n "$branch"; or set branch HEAD
    switch $url
        case "*bitbucket.org*"
            set url "$url/branch/$branch"
        case "*"
            set url "$url/tree/$branch"
    end
    printf "Opening in browser: %s\n" "$url"
    open "$url" # available on macOS
end

And I found a cool stuff from https://wstone.uk/blog/a-better-git-log-with-fish-abbreviations/

# Show last 5 commits.
abbr --add gl 'git log --oneline --graph -n 5'
# Show last n commits
function git_log_n
    echo -n "git log --oneline --graph -n "
    echo $argv | string match --regex '^gl(\d+)$' --groups-only
end
abbr --add gitlogn --regex '^gl\d+$' --function git_log_n

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