From 01a7ec2acf40d7dd3af654260c673baf4df7ae85 Mon Sep 17 00:00:00 2001 From: Joe Groocock Date: Wed, 18 May 2022 10:46:05 +0000 Subject: [PATCH] Dynamically identify the "default" git branch This broadly assumes that the "default" remote is called "origin", but that's better than assuming that plus the default branch name. Thanks to https://joshtronic.com/2020/08/09/how-to-get-the-default-git-branch/ Suggested-by: Chris Lane Signed-off-by: Joe Groocock --- aliases | 6 +++--- git/config | 1 + 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/aliases b/aliases index 40c478d..fb953c2 100644 --- a/aliases +++ b/aliases @@ -112,7 +112,7 @@ alias gitc='$EDITOR $XDG_CONFIG_HOME/git/config' alias ggignore='$EDITOR $XDG_CONFIG_HOME/git/gitignore' alias gcl="git clone --recursive" alias gco="git checkout" -alias gcom="git checkout master" +alias gcom="git checkout \"\$(git defbranch)\"" alias ga="git add" alias gap="git add -p" alias gau="git add -u" @@ -136,7 +136,7 @@ alias grba="grb --abort" alias grbc="grb --continue" alias grbsk="grb --skip" alias grbsh="grb --show-current" -alias grbom="git rebase origin/master" +alias grbom="git rebase \"origin/\$(git defbranch)\"" gfrb() { remote="${1%/*}"; git fetch "$remote" && git rebase "$@"; } gfrbi() { remote="${1%/*}"; git fetch "$remote" && git rebase -i "$@"; } @@ -160,7 +160,7 @@ alias gp="git push" alias gpf="gp --force" alias gpsu="git push --set-upstream" alias gpoH="git push origin HEAD" -alias gpsuom="git push --set-upstream origin master" +alias gpsuom="git push --set-upstream origin \"\$(git defbranch)\"" alias gpall="git remote | xargs -L1 git push" alias gl="git pull --rebase" alias glp="gl && gp" diff --git a/git/config b/git/config index eca0ba8..5886cbc 100644 --- a/git/config +++ b/git/config @@ -37,6 +37,7 @@ count = !echo $(pwd) && git rev-list HEAD --count unpushed = !git log --oneline @{u}..HEAD leaders = !git shortlog -s -n --all --no-merges + defbranch = !git symbolic-ref refs/remotes/origin/HEAD | sed \"s@^refs/remotes/origin/@@\" [advice] statusHints = false pushUpdateRejected = false