From e8e308340a078f081d48a2c6a1053978274555b4 Mon Sep 17 00:00:00 2001 From: Tim <45259958+carlfriedrich@users.noreply.github.com> Date: Sun, 13 Aug 2023 08:15:19 +0200 Subject: [PATCH] checkout_branch: support "-" argument (#322) 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 cf98013a..afb14642 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 "$@"