Home > Blockchain >  How do I change the default branch for my GitHub repo, given that the settings entry does not exist?
How do I change the default branch for my GitHub repo, given that the settings entry does not exist?

Time:03-11

To change the default branch, the instructions enter image description here

2. Here, the option does not exist

enter image description here

CodePudding user response:

You have no commits in your repository on GitHub, so it makes no sense to speak of a default branch or any branch1. If you had added a README or other file to your repo when you created it, you would see the option shown in your first screen shot. But you decided to create a completely empty repo2. So you won't see that option until you push from a local. Then, that option will appear.

Example! We create our repo at GitHub, calling it testing. As you show in your second screen shot, there is no default branch option. Now, on my own machine:

% mkdir testinggit
% cd testinggit
% git init
# make a file...
% git add .
% git commit -minit
% git remote add origin [email protected]:myusername/testing.git
% git push origin @

Now go back to GitHub and refresh the page, and sure enough, there's your missing option to set the default branch. The default branch is, by default, the one you push first, which in my case was main. Which is exactly what I wanted.

It might be useful also to realize that the concept of a "default branch" is pretty much bogus from a Git point of view. It isn't used for much of anything. I think it might be useful if you're going to do pull requests at GitHub, though, as it will be the branch chosen as the target branch for merging into by default when you create a pull request.


1. Though, to be sure, Git does have a notion of an "unborn branch". But let's not get into that now.
2. Perfectly reasonable.

  • Related