From da4e2b14657895b4604a78e0f674028d650a6e22 Mon Sep 17 00:00:00 2001
From: Raul Benencia <raul@thousandeyes.com>
Date: Wed, 17 Apr 2024 10:26:30 -0700
Subject: sh: convert a few git aliases to functions

---
 .alias.d/10-git | 25 ++++++++++++++++++++++---
 1 file changed, 22 insertions(+), 3 deletions(-)

diff --git a/.alias.d/10-git b/.alias.d/10-git
index 9bb1906..ac82cda 100644
--- a/.alias.d/10-git
+++ b/.alias.d/10-git
@@ -29,7 +29,6 @@ alias gcf='git config --list'
 alias gcl='git clone --recursive'
 alias gclean='git clean -fd'
 alias gpristine='git reset --hard && git clean -dfx'
-alias gcm='git checkout master && git fetch upstream && git reset --hard upstream/master'
 alias gco='git checkout'
 alias gcount='git shortlog -sn'
 
@@ -126,8 +125,28 @@ alias gwch='git whatchanged -p --abbrev-commit --pretty=medium'
 alias gwip='git add -A; git rm $(git ls-files --deleted) 2> /dev/null; git commit -m "--wip--"'
 alias git-delete-merged-branches='git branch --merged | grep -v "\*" | grep -v master | xargs -n 1 git branch -d'
 alias gfrh='git fetch && git reset --hard "origin/$(git rev-parse --abbrev-ref HEAD)"'
-alias gfr='git fetch upstream && git rebase upstream/master'
 
 # mr
 alias ms='mr -m status'
-alias mp='mr push'
\ No newline at end of file
+alias mp='mr push'
+
+main_branch() {
+  if git branch  --list | grep -q master; then
+    echo master
+  else
+    echo main
+  fi
+}
+
+gcm() {
+  branch=$(main_branch)
+  git checkout "$branch"
+  git fetch upstream
+  git reset --hard "upstream/${branch}"
+}
+
+gfr() {
+  branch=$(main_branch)
+  git fetch upstream
+  git rebase "upstream/${branch}"
+}
-- 
cgit v1.2.3