Merge branch 'nd/switch-and-restore'
[gitweb.git] / builtin / checkout.c
index 0a3679eb776ec962d943f3d1902c9c6e7f1feea7..12837277615d3985fb995862c22ededfed728b8a 100644 (file)
@@ -1708,6 +1708,15 @@ int cmd_checkout(int argc, const char **argv, const char *prefix)
        opts.checkout_index = -2;    /* default on */
        opts.checkout_worktree = -2; /* default on */
 
+       if (argc == 3 && !strcmp(argv[1], "-b")) {
+               /*
+                * User ran 'git checkout -b <branch>' and expects
+                * the same behavior as 'git switch -c <branch>'.
+                */
+               opts.switch_branch_doing_nothing_is_ok = 0;
+               opts.only_merge_on_switching_branches = 1;
+       }
+
        options = parse_options_dup(checkout_options);
        options = add_common_options(&opts, options);
        options = add_common_switch_branch_options(&opts, options);