Skip to content

Commit e8e3083

Browse files
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
1 parent b663d22 commit e8e3083

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

bin/git-forgit

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,7 @@ _forgit_checkout_branch() {
454454
_forgit_inside_work_tree || return 1
455455
# if called with arguments, check if branch exists, else create a new one
456456
if [[ $# -ne 0 ]]; then
457-
if git show-branch "$@" &>/dev/null; then
457+
if [[ "$*" == "-" ]] || git show-branch "$@" &>/dev/null; then
458458
git switch "$@"
459459
else
460460
git switch -c "$@"

0 commit comments

Comments
 (0)