@@ -556,6 +556,15 @@ static void copy_or_rename_branch(const char *oldname, const char *newname, int
replace_each_worktree_head_symref(oldref.buf, newref.buf, logmsg.buf))
die(_("Branch renamed to %s, but HEAD is not updated!"), newname);
+ if (!copy) {
+ char *main_branch = git_main_branch_name(0);
+
+ if (!strcmp(interpreted_oldname, main_branch))
+ git_config_set("core.mainbranch", interpreted_newname);
+
+ free(main_branch);
+ }
+
strbuf_release(&logmsg);
strbuf_addf(&oldsection, "branch.%s", interpreted_oldname);
@@ -467,6 +467,15 @@ EOF
test_cmp expect actual
'
+test_expect_success 'renaming the main branch modifies core.mainBranch' '
+ git init rename-main &&
+ test_commit -C rename-main initial &&
+ git -C rename-main branch -m trunk &&
+ git -C rename-main config core.mainBranch >actual &&
+ echo trunk >expect &&
+ test_cmp expect actual
+'
+
test_expect_success 'git branch -c dumps usage' '
test_expect_code 128 git branch -c 2>err &&
test_i18ngrep "branch name required" err