DrWatson.jl icon indicating copy to clipboard operation
DrWatson.jl copied to clipboard

Have initialize_project() initialize the git repo with a `main` branch instead of `master`.

Open thompsonmj opened this issue 3 years ago • 8 comments

Have initialize_project() initialize the git repo with a main branch instead of master.

The git command is simply git branch -m master main.

Still learning Julia, so I'm not quite sure how to make a PR with an edit to the source.

While it's true a user can configure their git to default to main with git config --global init.defaultBranch main, this would be a beneficial change for DrWatson to have by default until the baked in default for git is main.

thompsonmj avatar May 13 '21 16:05 thompsonmj

Why should the default branch be named main instead of master ? If git defaults to master perhaps it is a good choice?

Datseris avatar May 13 '21 17:05 Datseris

It's a DEI update. GitHub has already implemented a switch to default a new repo's primary branch as main.

For context, see this article.

And from the git docs for git init, the official default is still master, but I've seen around that they plan to migrate to using main.

-b --initial-branch= Use the specified name for the initial branch in the newly created repository. If not specified, fall back to the default name (currently master, but this is subject to change in the future; the name can be customized via the init.defaultBranch configuration variable).

thompsonmj avatar May 13 '21 19:05 thompsonmj

ok, this sounds like a trivial "fix" then.

Datseris avatar May 13 '21 19:05 Datseris

I just tried to solve this, and it is hard. Because we need to do it through the LibGit2 standard library, but I have no idea how to use that to rename a branch, or to check what is the name of the existing branch.

Datseris avatar Jul 16 '22 23:07 Datseris

Seems like using Git.jl is the only way. We also can do the simple:

git config --global init.defaultBranch <name>

With the $(git()) that Git.jl provides, to not worry about this anymore.

Datseris avatar Jul 17 '22 18:07 Datseris

Yes, tried making a new project with DW after changing the global git config default branch and main popped right out. Thanks!

thompsonmj avatar Jul 24 '22 18:07 thompsonmj

I set it to closed because I realized it might not be good to change a user's global git config settings while setting up a DrWatson project:

Changing the name of a branch like master/main/mainline/default will break the integrations, services, helper utilities and build/release scripts that your repository uses. Before you do this, make sure you consult with your collaborators. Also, make sure you do a thorough search through your repo and update any references to the old branch name in your code and scripts.

I could imagine someone having templates for such helper utilities that they apply to new repos, and messing with their git config might interupt something? And maybe just having the option to change the default branch name through this config is enough.

thompsonmj avatar Jul 24 '22 19:07 thompsonmj

That sounds valid. However, the reason I re-opened this is because the issue request still stands. DrWatson should try to initialize a repo with main instead of master. If global config is a bad idea, other ideas using git are surely possible like simply git branch -M old new.

Datseris avatar Jul 24 '22 19:07 Datseris

I just checked if this was still an issue (before trying my hands on fixing it). To test it, I changed my own global git setting to name default branches "Testbranch". (git config --global init.defaultBranch Testbranch) All my now created repositories will have their branch called "Testbranch". When I use DWs initialize_project() the created repositoriy's branch is named "main" again.

I could not find the commit (if any) that fixed this, but it seems to me that this issue is no longer a problem.

Myrkwid avatar Mar 08 '23 12:03 Myrkwid

I have fixed it, but DrWatson constantly throws a warning that "the defualt branch could not be renamed to "main"". So I don't know why it throws the warning, even though it does succeed in the rename. Here is the code that triggers the warning: https://github.com/JuliaDynamics/DrWatson.jl/blob/main/src/project_setup.jl#L311

Datseris avatar Mar 08 '23 13:03 Datseris