From ae3b0ec4e8bab091f12e73fc4612b457470c81ec Mon Sep 17 00:00:00 2001 From: Victor Westerlund Date: Sun, 11 Jan 2026 01:11:48 +0100 Subject: [PATCH] feat(git): add create and checkout branch as new gitf `cb` case (#102) Reviewed-on: https://codeberg.org/vlw/dotfiles/pulls/102 --- .bash_aliases | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/.bash_aliases b/.bash_aliases index 9b7e9a4..870b977 100644 --- a/.bash_aliases +++ b/.bash_aliases @@ -162,18 +162,33 @@ gitf () { gitf ;; - # Checkout [and create] a git branch (defaults to "master") + # Checkout a git branch (defaults to "master") "b") local branch="${2:-master}" - if git show-ref --verify --quiet refs/heads/"$branch"; then - git checkout $branch + if ! git show-ref --verify --quiet refs/heads/"$branch"; then gitf + echo "" + echo -e "\e[0;91mNo such branch '$branch'\e[0m" + return 0 + fi + + git checkout $branch + gitf + ;; + + # Checkout [and create] a git branch (defaults to "master") + "cb") + local branch="${2:-master}" + + # Checkout existing branch + if git show-ref --verify --quiet refs/heads/"$branch"; then + gitf b $branch return 0 fi git checkout -b $branch - gitf + gitf b $branch ;; # Pull current branch from a remote (defaults to "origin"). "d" for download.