dotfiles/.config/fish/functions/git_main_branch.fish

12 lines
396 B
Fish
Raw Normal View History

2024-12-15 22:46:38 +00:00
function git_main_branch -d 'Detect name of main branch of current git repository'
# heuristic to return the name of the main branch
command git rev-parse --git-dir &> /dev/null || return
for ref in refs/{heads,remotes/{origin,upstream}}/{main,master,trunk}
if command git show-ref -q --verify $ref
echo (string split -r -m1 -f2 / $ref)
return
end
end
echo main
end