From 7096b15e8592f9d292f4b604b41d94c97880c8ec Mon Sep 17 00:00:00 2001 From: Rob Watson Date: Fri, 7 Jul 2023 12:08:50 +0200 Subject: [PATCH] chore: add gitmainbranch --- gitconfig | 9 +++++---- script/gitmainbranch | 17 +++++++++++++++++ 2 files changed, 22 insertions(+), 4 deletions(-) create mode 100755 script/gitmainbranch diff --git a/gitconfig b/gitconfig index bac91d2..cadafc9 100644 --- a/gitconfig +++ b/gitconfig @@ -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 diff --git a/script/gitmainbranch b/script/gitmainbranch new file mode 100755 index 0000000..f17a5b1 --- /dev/null +++ b/script/gitmainbranch @@ -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