From 432b642a16239581fdf6e4d101a548a741df6842 Mon Sep 17 00:00:00 2001 From: carlfriedrich Date: Thu, 10 Aug 2023 15:00:54 +0200 Subject: [PATCH] checkout_branch: support "-" argument git natively supports `-` as an argument to `git switch` and `git checkout`. It is shorthand for `@{-1}`, which is a way to refer to the last branch you were on. forgit used to interpret `-` as a branch name, detect that it does not exist yet and create a new one with this name, which does not work. Add a check whether `-` is passed on the command line and do not create a new branch in this case --- bin/git-forgit | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/git-forgit b/bin/git-forgit index cf98013..afb1464 100755 --- a/bin/git-forgit +++ b/bin/git-forgit @@ -454,7 +454,7 @@ _forgit_checkout_branch() { _forgit_inside_work_tree || return 1 # if called with arguments, check if branch exists, else create a new one if [[ $# -ne 0 ]]; then - if git show-branch "$@" &>/dev/null; then + if [[ "$*" == "-" ]] || git show-branch "$@" &>/dev/null; then git switch "$@" else git switch -c "$@"