Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change default git branch name to Main instead of Master #8926

Closed
NangiDev opened this issue Dec 1, 2020 · 11 comments
Closed

Change default git branch name to Main instead of Master #8926

NangiDev opened this issue Dec 1, 2020 · 11 comments
Labels
C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted`

Comments

@NangiDev
Copy link

NangiDev commented Dec 1, 2020

When running

cargo new project-name --bin

The generated project initiates git with default branch name master.

My suggestion is that when running the new project command the default branch name should be main

I know it's not a universal agreement that git branches using main as default now a days, but it is has been growing. Also GitHub that this project is hosted on has decided on main.


Debugging steps:

$ cargo --version
$ git --version
$ git config --show-origin --get init.defaultBranch
@NangiDev NangiDev added the C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted` label Dec 1, 2020
@NangiDev
Copy link
Author

NangiDev commented Dec 1, 2020

Could be a duplicate of cargo init and use HEAD instead

Also I found out that using a git-template could fix this for me if we decides to keep it as is

@LordSentox
Copy link

I think a reason for keeping master as the main branch and hopefully without getting too political would be that when calling git init the default branch is still master eventhough some websites have changed their behaviour. Could this be more of a git issue than a cargo issue?

@Nemo157
Copy link
Member

Nemo157 commented Dec 1, 2020

You need to just configure your git, I have init.defaultBranch = prīmum in my ~/.gitconfig and:

/tmp/tmp.qSrokxe56d > cargo new foo
     Created binary (application) `foo` package
/tmp/tmp.qSrokxe56d > cd foo
/tmp/tmp.qSrokxe56d/foo on prīmum >

@NangiDev
Copy link
Author

NangiDev commented Dec 1, 2020

I think a reason for keeping master as the main branch and hopefully without getting too political would be that when calling git init the default branch is still master eventhough some websites have changed their behaviour. Could this be more of a git issue than a cargo issue?

Yes it makes sense. I guess you could look at changing to main to be a custom config on these websites part. So staying with git standard makes sense to me. Also I found the git-template solution. I think that is a valid solution for people who want main as default.

You need to just configure your git, I have init.defaultBranch = prīmum in my ~/.gitconfig and:

/tmp/tmp.qSrokxe56d > cargo new foo
     Created binary (application) `foo` package
/tmp/tmp.qSrokxe56d > cd foo
/tmp/tmp.qSrokxe56d/foo on prīmum >

This is a good solution for me. Thanks. I'm guessing this is a global gitconfig right? So it would change all my future git inits.

@NangiDev
Copy link
Author

NangiDev commented Dec 1, 2020

Closing issue.
The "workaround" Nemo157 mentioned is a good solution.

@NangiDev NangiDev closed this as completed Dec 1, 2020
@scottshambaugh
Copy link

scottshambaugh commented Aug 14, 2022

To give a one-liner that accomplishes this, run the following in a terminal:

git config --global init.defaultBranch 'main'

@indianakernick
Copy link

I ran git init and it uses main. I ran cargo new and it uses master. Perhaps something changed?

@Nemo157
Copy link
Member

Nemo157 commented Jul 7, 2023

I can't reproduce locally on macOS, without configuration both git (2.41.0) and cargo (latest nightly) use master, with configuration both use the configured value.

@indianakernick What do git config --get init.defaultBranch, git --version and cargo --version say?

One thing I notice is that cargo uses libgit2 to initialize the repository, which I presume queries the config and has a hard-coded default of master. If you have a version of git patched to use a different default (which hasn't happened upstream, but maybe some distros patch it?) then they may differ if you don't manually set it (which is why git init when unconfigured emits a warning telling you to set it in the config).

@indianakernick
Copy link

I'm also on macOS but I'm using the version of git that's bundled with Xcode.

> git config --get init.defaultBranch
main
> git --version
git version 2.39.2 (Apple Git-143)
> cargo --version
cargo 1.70.0 (ec8a8a0ca 2023-04-25)

@Nemo157
Copy link
Member

Nemo157 commented Jul 7, 2023

Maybe the config is set in a different config file that libgit2 doesn't check, try git config --show-origin --get init.defaultBranch to see exactly where the setting is coming from.

@indianakernick
Copy link

I get /Applications/Xcode.app/Contents/Developer/usr/share/git-core/gitconfig. That's probably it then. It doesn't look in this Xcode-specific place. Makes sense. Probably not a bug.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted`
Projects
None yet
Development

No branches or pull requests

5 participants