From 602acc711a4deef20455b8358132ebc447f3d333 Mon Sep 17 00:00:00 2001 From: Roy Attias Date: Fri, 2 Dec 2022 21:28:14 +0200 Subject: [PATCH 1/3] aliases: git: Modernize get default branch function --- aliases/available/git.aliases.bash | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/aliases/available/git.aliases.bash b/aliases/available/git.aliases.bash index 535665b14d..9b71859948 100644 --- a/aliases/available/git.aliases.bash +++ b/aliases/available/git.aliases.bash @@ -200,9 +200,5 @@ function gdv() { } function get_default_branch() { - if git branch | grep -q '^. main\s*$'; then - echo main - else - echo master - fi + git symbolic-ref refs/remotes/origin/HEAD | sed 's@^refs/remotes/origin/@@' } From 54cdf3a60aa0540cf7809f6d8a953cf428d521b2 Mon Sep 17 00:00:00 2001 From: Roy Attias Date: Fri, 2 Dec 2022 21:24:34 +0200 Subject: [PATCH 2/3] aliases: git: Modernize 'gpf' and make it use --force-with-lease --- aliases/available/git.aliases.bash | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/aliases/available/git.aliases.bash b/aliases/available/git.aliases.bash index 9b71859948..aa106b572b 100644 --- a/aliases/available/git.aliases.bash +++ b/aliases/available/git.aliases.bash @@ -103,7 +103,8 @@ alias gpatch='git format-patch -1' # push alias gp='git push' alias gpd='git push --delete' -alias gpf='git push --force' +alias gpf='git push --force-with-lease' +alias gpff='git push --force' alias gpo='git push origin HEAD' alias gpom='git push origin $(get_default_branch)' alias gpu='git push --set-upstream' From d9c339cf2956e24e5b3e67696c812dcdcd8ac07f Mon Sep 17 00:00:00 2001 From: Roy Attias Date: Sun, 4 Dec 2022 17:35:44 +0200 Subject: [PATCH 3/3] aliases: git: Don't use sed for extracting branch name --- aliases/available/git.aliases.bash | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/aliases/available/git.aliases.bash b/aliases/available/git.aliases.bash index aa106b572b..11ea2518d1 100644 --- a/aliases/available/git.aliases.bash +++ b/aliases/available/git.aliases.bash @@ -201,5 +201,6 @@ function gdv() { } function get_default_branch() { - git symbolic-ref refs/remotes/origin/HEAD | sed 's@^refs/remotes/origin/@@' + branch=$(git symbolic-ref refs/remotes/origin/HEAD) + ${branch#refs/remotes/origin/} }