diff --git a/config/fish/functions.fish b/config/fish/functions.fish index 7435bc8..a117772 100644 --- a/config/fish/functions.fish +++ b/config/fish/functions.fish @@ -10,12 +10,19 @@ function cheat --description "help " curl "cht.sh/$argv[1]/$args" end -# update master and create a branch with value: $1 +# update the default branch and create a fresh branch with value: $1 function gitissue if test -z "$argv[1]" echo "usage: gitissue " return 1 end + # Detect the remote's default branch instead of assuming `master`, + # so this works on repos that use `main` (or anything else). + set -l default (git symbolic-ref --quiet --short refs/remotes/origin/HEAD 2>/dev/null | string replace 'origin/' '') + if test -z "$default" + echo "Could not determine origin's default branch; run 'git remote set-head origin -a' first." + return 1 + end # `git reset --hard` discards uncommitted work, so confirm first. if not git diff --quiet; or not git diff --cached --quiet read -P "Uncommitted changes will be DISCARDED. Continue? [y/N] " -n 1 reply @@ -25,7 +32,7 @@ function gitissue end end git reset --hard - git checkout master - git pull origin master + git checkout $default + git pull origin $default git checkout -b $argv[1] end