Skip to main content



      Home
Home » Eclipse Projects » EGit / JGit » Create a main branch, not master
Create a main branch, not master [message #1860096] Mon, 17 July 2023 13:07 Go to next message
Eclipse UserFriend
How do I get EGit to create a main branch for the initial commit and push?

This is a very beginner question. I have tried to find answers but wherever the answer exists, it is too complicated for me to understand.

I have been doing the following; I can do this much. I can create an Eclipse project and create a local repository for it. I can create a GitHub repository and specify the SSH connection for it in EGit. Then when I do a commit and push it says the branch is unborn and the master branch will be created. My GitHub account is set to use main for the default branch. I ignore the message and do the push then I do something to clean things up. I am not sure what, I think I do a rename of something somewhere.

I have been unable to find an answer to the question of how to specify use of main for the branch for the initial commit and push.
Re: Create a main branch, not master [message #1860108 is a reply to message #1860096] Tue, 18 July 2023 06:13 Go to previous messageGo to next message
Eclipse UserFriend
Doesn't git config --global init.defaultBranch = main (before cloning or creating a new repository) work? See the git config documentation.
Re: Create a main branch, not master [message #1860122 is a reply to message #1860108] Tue, 18 July 2023 15:46 Go to previous messageGo to next message
Eclipse UserFriend
Thomas Wolf wrote on Tue, 18 July 2023 06:13
Doesn't git config --global init.defaultBranch = main (before cloning or creating a new repository) work? See the git config documentation.

Then I assume this is not supported by EGit in the sense that I must use the git command to do that. That is okay but I am trying to clarify things.

I do not see that mentioned in EGit/User Guide - Eclipsepedia. I think it would also help for it to be mentioned in Egit Tutorial.

Except it might not be what I am asking about. When I do:
git config --list --show-origin

I get:
init.defaultbranch=main

Therefore I assume that init.defaultbranch was already set to main and issuing the specified command to change it would change nothing.

[Updated on: Tue, 18 July 2023 15:48] by Moderator

Re: Create a main branch, not master [message #1860123 is a reply to message #1860122] Tue, 18 July 2023 16:25 Go to previous messageGo to next message
Eclipse UserFriend
What version of EGit are you using?

In which file exactly is this setting present in your environment?

[Updated on: Tue, 18 July 2023 16:29] by Moderator

Re: Create a main branch, not master [message #1860124 is a reply to message #1860123] Tue, 18 July 2023 16:30 Go to previous messageGo to next message
Eclipse UserFriend
BTW: this git config can also be set via the EGit UI. I just gave the command-line git command since that's easier.
Re: Create a main branch, not master [message #1860125 is a reply to message #1860123] Tue, 18 July 2023 16:45 Go to previous messageGo to next message
Eclipse UserFriend
Thomas Wolf wrote on Tue, 18 July 2023 16:25
What version of EGit are you using?

In which file exactly is this setting present in your environment?

I do not know the version. I tried to find where the version is specified but I do not know where. I did recently update to the latest version but I do not know what the version was prior to the update, I tried to find that.

I am not sure I understand what you mean by environment. I issued the command I posted using a Windows command prompt. Okay, sorry. The relevant complete output lines are:

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


I see there is a difference. Sorry. I edited the C:/Program Files/Git/etc/gitconfig file and changed it there. I will see if that works.
Re: Create a main branch, not master [message #1860127 is a reply to message #1860125] Tue, 18 July 2023 18:36 Go to previous messageGo to next message
Eclipse UserFriend
In "Window" | "Preferences" when I go to "Version Control (Team)" | "Git" | "Configuration" the init.defaultBranch is Main. I would have changed that if it was Master.

With the init.defaultBranch set to Main (in the files I specified previously), when I create a new project in Eclipse and create a repository (share) then EGit is still saying that the Master branch will be created.

[Updated on: Tue, 18 July 2023 19:01] by Moderator

Re: Create a main branch, not master [message #1860130 is a reply to message #1860127] Wed, 19 July 2023 03:01 Go to previous messageGo to next message
Eclipse UserFriend
The configuration looks fine. No idea why it told you something about an unborn branch "master".

The EGit version can be found via "About Eclipse, Installation details", then on the "Installed Software" tab look for "Eclipse EGit" or for "Git integration for Eclipse".
Re: Create a main branch, not master [message #1860179 is a reply to message #1860130] Thu, 20 July 2023 16:37 Go to previous messageGo to next message
Eclipse UserFriend
I think the problem I am trying to describe is the same as in How to change default github branch in eclipse egit from master to main? - Stack Overflow. I apologize for not being able to describe the situation accurately. I think that 564794 Allow to configure default branch name is supposed to solve the problem but I think the last post describes what is happening to me and indicates it is not working.

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

When creating a repository using the git init command it is possible to specify the branch. Egit does not support that, correct? We cannot specify the branch in the form for creating a repository. Bug 564794 (as above) mentions a new option core.defaultBranch and it seems to say it is called init.defaultbranch in the implementation but either I am missing something or it is not working. It might help to be able to specify a branch when creating a repository in a manner that corresponds with the git init command.

[Updated on: Thu, 20 July 2023 16:38] by Moderator

Re: Create a main branch, not master [message #1860180 is a reply to message #1860179] Thu, 20 July 2023 16:43 Go to previous messageGo to next message
Eclipse UserFriend
When I create a new repository via EGit, I get a dialog where I can even specify that initial branch name, and it just works for me. So the equivalent of git init -b <branch-name> does exist in EGit.
Re: Create a main branch, not master [message #1860185 is a reply to message #1860180] Thu, 20 July 2023 18:38 Go to previous messageGo to next message
Eclipse UserFriend
The following is the dialog I get for creating a repository. I do not see where to specify a branch.
https://dsm04pap002files.storage.live.com/y4mRuD5l7sTKHLzCUW0rLKODKxGXFVaoX640taJ7SvTr3XFECsUeredjQd7rloaUuZhtZhOOMNJ49MtkdVC0WNSxY8zsv31abxgj7tWxW0roSnrbgMrTgfaynoP8W6qwK0EQ9WZXUKaPPk70nP7xj3maUl5xrQKO5mSNa58mHvi7fm_wQkNY2Lv5YEaTpgRn1y4?encodeFailures=1&width=747&height=431
Re: Create a main branch, not master [message #1860188 is a reply to message #1860185] Fri, 21 July 2023 04:36 Go to previous messageGo to next message
Eclipse UserFriend
I see. You create the project first, then share it and create the git repo through that. I create the repo first (in the git repositories view), later share the project into that then already existing git repo.

I'll give it a try later. Maybe there's a bug somewhere.

BTW: git is made to work on a local disk. Having your git repo on some shared drive is asking for trouble; it'll hurt performance. And I hope your Eclipse workspace isn't on a shared drive either. That might hurt Eclipse performance in general. Having Eclipse projects on shared drives is probably also not optimal. Is "OneDrive" on a local disk?
Re: Create a main branch, not master [message #1860203 is a reply to message #1860188] Fri, 21 July 2023 16:28 Go to previous messageGo to next message
Eclipse UserFriend
Thomas Wolf wrote on Fri, 21 July 2023 04:36
I see. You create the project first, then share it and create the git repo through that.
I think that is the way all the tutorials and such say to do it.

Thomas Wolf wrote on Fri, 21 July 2023 04:36
I create the repo first (in the git repositories view), later share the project into that then already existing git repo.
I might not understand how to do it that way but I will try, at least for the experience.

Thomas Wolf wrote on Fri, 21 July 2023 04:36
BTW: git is made to work on a local disk.

I am not sure how it works but I assume Microsoft's OneDrive caches files locally. The files appear to applications as local files.

Thomas Wolf wrote on Fri, 21 July 2023 04:36
Having your git repo on some shared drive is asking for trouble; it'll hurt performance. And I hope your Eclipse workspace isn't on a shared drive either. That might hurt Eclipse performance in general. Having Eclipse projects on shared drives is probably also not optimal. Is "OneDrive" on a local disk?


Yes it is all in Microsoft's OneDrive. It does not seem to be a problem for performance. Windows 11 has support of OneDrive built into it. I was skeptical too but it seems to work well. Google Drive is supported in Windows in a manner that Microsoft OneDrive is.

Eclipse starts much faster in this system that uses OneDrive for my Documents directory but the improved performance probably is due to more processing power in this system. My previous system had 8 core and used a local (SSD) disk for the Documents. This system has 16 core and uses OneDrive and Eclipse starts much faster (I cannot think of a reason why).
Re: Create a main branch, not master [message #1860205 is a reply to message #1860203] Sat, 22 July 2023 05:55 Go to previous messageGo to next message
Eclipse UserFriend
Indeed there is a bug, tracked now as bug 582225.
Re: Create a main branch, not master [message #1860207 is a reply to message #1860205] Sat, 22 July 2023 09:59 Go to previous message
Eclipse UserFriend
Thank you. That explains it.
Previous Topic:Using commit command on JGit cause no diff changes
Next Topic:Unexpected reply from ssh-agent: SSH_AGENT_FAILURE
Goto Forum:
  


Current Time: Sat May 17 01:22:48 EDT 2025

Powered by FUDForum. Page generated in 0.04884 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top