chore: add gitmainbranch

This commit is contained in:
Rob Watson 2023-07-07 12:08:50 +02:00
parent 6d02791a65
commit 7096b15e85
2 changed files with 22 additions and 4 deletions

View File

@ -30,12 +30,12 @@
cpls = !git cp $(git ls)
d = diff
dls = !git diff $(git branch | fzf)
dom = diff origin/master...
dom = !git diff origin/$(git mainbranch)...
drb = !git diff $(git rb)
ds = diff --staged
f = fetch
fc = commit --allow-empty -m 'Initial commit'
fixom = !sh -c 'git fetch && git rebase -i --autosquash origin/master'
fixom = !sh -c 'git fetch && git rebase -i --autosquash origin/$(git mainbranch)'
fixup = rebase -i --autosquash
l = log
l1 = log --oneline
@ -44,6 +44,7 @@
lm = logme
logme = !sh -c 'git log --author=\"$(git config --get user.name)\"'
ls = !git branch --format '%(refname:short)' | fzf
mainbranch = !gitmainbranch
mls = !git merge $(git ls)
mr = !git merge $(git rb)
mrb = mr
@ -57,7 +58,7 @@
plr = pull --rebase
ph = push -u origin HEAD
pr = dom
prs = diff --stat origin/master
prs = !git diff --stat origin/$(git mainbranch)
ra = rebase --abort
rb = !git rev-parse --abbrev-ref --symbolic-full-name @{u}
rc = rebase --continue
@ -66,7 +67,7 @@
rh = reset --hard
ri = rebase -i --autosquash
rils = !git rebase -i --autosquash $(git branch | fzf)
rom = !sh -c 'git fetch && git rebase origin/master'
rom = !sh -c 'git fetch && git rebase origin/$(git mainbranch)'
rr = !sh -c 'git fetch && git reset --hard $(git rb)'
rv = revert
rvh = revert HEAD

17
script/gitmainbranch Executable file
View File

@ -0,0 +1,17 @@
#!/usr/bin/env bash
#
# Try to detect if the current repo has a main branch, or master.
set -e
if git branch -l | grep -q "main"; then
echo "main"
exit 0
fi
if git branch -l | grep -q "master"; then
echo "master"
exit 0
fi
exit 1