Git in Eclipse creates "master" branch instead of "main" branch

This question is not specific to websites but currently I am doing this for websites and I do not know what other category to use.

I am using Eclipse to develop simple websites. Egit is the Eclipse extension for Git. I do the following:

  • create a project in Eclipse
  • create a local repository using “Share Project”
  • create a repository in GitHub
  • add (create) a remote repository to the project for the repository in GitHub

Egit will create a master branch. My GitHub repositories are created with main as the default branch.

When I issue the command:
git config --list --show-origin

The following two lines show configuartions for defaultbranch:

file:C:/Program Files/Git/etc/gitconfig init.defaultbranch=main
file:C:/Users/sam/.gitconfig    init.defaultbranch=main

I do not know why Egit wants to create a master branch.

When I do the preceding to create a project for testing purposes, the HEAD file contains:
ref: refs/heads/master

I do not know why that is set to master.

I have created a question in the Egit forum in the Eclipse forums but I am not getting much help. Is this something I should ask about in a Git forum instead? Hopefully someone here can help.

Here is a useful stack overflow thread to answer your question…

In case you were curious, here is an article explaining why the change from master to main was made.

Thank you. I think I understand why GitHub is changing from master to main and that is why I want to.

I did do many searches and I did not find those articles. And the Egit people either do not know about them or just did not tell me.

I do not understand the instructions describing How to push from local master branch to github main branch in eclipse EGit but perhaps because there is not yet a local master branch.

The most important thing is 564794 – Allow to configure default branch name. I think it is saying it should work but the last comment indicates it does not work, that they get the behavior I am getting.

I think I can just change master to main in that file after creating the local repository. Then when I push, the branch is named main.

It seems that the issue you’re facing is related to the default branch name used by Git and Egit in Eclipse. Before Git 2.28, the default branch name was “master,” but since then, Git has moved towards using “main” as the default branch name to promote more inclusive language.

Egit in Eclipse might not have adopted this change automatically, which is why it’s still creating a “master” branch by default when initializing a new repository. The default branch name is specified in the Git configuration file, which you observed with the git config --list --show-origin command.

To address this issue, you can manually change the default branch name in Egit’s configuration to “main” instead of “master.” You can do this by executing the following command in your Git repository:

git config --local init.defaultBranch main

This command sets the default branch for your current repository to “main.” Additionally, you can change the global Git configuration to use “main” as the default branch for all repositories you create:

git config --global init.defaultBranch main

By updating the default branch name in the Git configuration, Egit should now create new repositories with “main” as the default branch instead of “master.”

As for the “HEAD” file containing “ref: refs/heads/master,” it is expected if your current branch is still called “master.” However, after you set the default branch to “main” using the configuration commands, any new repositories should have “main” as the default branch, and the “HEAD” file will reference that instead.

If you encounter any issues or if Egit behaves differently, seeking help in a Git forum is a reasonable step, as Git experts might have more specific insights into Egit’s behavior and potential workarounds.

Perhaps I misunderstand something. As I said previously, I think that init.defaultBranch is already main for the two configuration files in my system. I think that is the situation. If I understand things then main should be the default.

Except as best as I understand, it is not doing that.

My Eclipse Community Forums thread is EGit / JGit » Create a main branch, not master.

That thread identified the bug 582225 – Creating a repository in the "Team->Share…" dialog ignores init.defaultBranch.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.