DrWatson.jl
DrWatson.jl copied to clipboard
Have initialize_project() initialize the git repo with a `main` branch instead of `master`.
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.
Why should the default branch be named main
instead of master
? If git defaults to master
perhaps it is a good choice?
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).
ok, this sounds like a trivial "fix" then.
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.
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.
Yes, tried making a new project with DW after changing the global git config default branch and main popped right out. Thanks!
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.
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
.
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.
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