0

When creating the master base repository from a workspace I made a mistake that I realized only significant time later:

The default branch is not master, but some merge branch like post-merge. So I want the default branch to be master instead, but I don't know how to do that:

In a workspace I would simply git checkout master, then delete the other branch. But obviously in a bare repository I cannot checkout.

U. Windl
  • 3,480
  • 26
  • 54
  • Do you mean `git symbolic-ref HEAD refs/heads/trunk`, or do you mean `git config --global init.defaultBranch main`? – U. Windl Mar 15 '22 at 09:01
  • From the linked question - _"For bare repos, you cannot run git checkout (that's what it means to be bare). Instead, you can change HEAD to point at a different branch: `git init --bare; git symbolic-ref HEAD refs/heads/trunk`"_ – evolutionxbox Mar 15 '22 at 09:05
  • Sorry, I don't understand: Doesn't `git init` create a new repository? My repository exists already. So I guess I only need the second command. – U. Windl Mar 15 '22 at 09:18
  • Yes. Take from the answer what you need. You don't need `git init --bare` if you already have a repo – evolutionxbox Mar 15 '22 at 09:19
  • https://stackoverflow.com/q/42871542/6607497 is specifically on creating a new repository, while my question is for an existing repository. I'd like to be able to provide an answer here, but I cannot as the question is closed now. – U. Windl Mar 15 '22 at 09:21
  • https://stackoverflow.com/a/42871621/989920 answers this question. `git symbolic-ref HEAD refs/heads/new-default-branch-name` will do what you want. Just make sure the branch `new-default-branch-name` already exists. – evolutionxbox Mar 15 '22 at 13:04
  • OK, fixed my problem, but stil lI think providing a specific answer to this question would be a good thing. I see other questions having 80% duplicate answers (that is most answers say practically the same) that are not deleted, but this is not accepted to be a valid question. – U. Windl Mar 15 '22 at 15:04
  • If SO allowed that, then we'd have millions of "how to format date in JS" questions, because they're all _slightly_ different. – evolutionxbox Mar 15 '22 at 16:34
  • No, because the title has a correct summary. There's a fundamental difference between "create a new git branch with a different name" and "Make an existing branch the default branch", even when an answer to one question will help to answer a *different* question, too. – U. Windl Mar 16 '22 at 08:14
  • I think we'll have to agree to disagree on that. I'm also not the only one who thinks this since the question was closed. I still believe this question is answered by the linked one. – evolutionxbox Mar 16 '22 at 08:17

0 Answers0