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

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

Closed
thompsonmj opened this issue May 13, 2021 · 10 comments · Fixed by #381
Closed
Labels
good first issue Easy issue good for newcomers help wanted The developers need some help here! project-setup Related to the functionality "Project setup"

Comments

@thompsonmj
Copy link
Contributor

thompsonmj commented May 13, 2021

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 thompsonmj changed the title 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. May 13, 2021
@Datseris
Copy link
Member

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

@Datseris Datseris added the discussion Let's talk about how things should be! label May 13, 2021
@thompsonmj
Copy link
Contributor Author

thompsonmj commented May 13, 2021

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).

@Datseris Datseris added good first issue Easy issue good for newcomers and removed discussion Let's talk about how things should be! labels May 13, 2021
@Datseris
Copy link
Member

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

@Datseris Datseris added the project-setup Related to the functionality "Project setup" label May 24, 2021
@Datseris Datseris changed the title 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. Dec 4, 2021
@Datseris Datseris added the help wanted The developers need some help here! label Jul 16, 2022
@Datseris
Copy link
Member

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
Copy link
Member

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.

@thompsonmj
Copy link
Contributor Author

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

@Datseris Datseris reopened this Jul 24, 2022
@thompsonmj
Copy link
Contributor Author

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.

@Datseris
Copy link
Member

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.

@Myrkwid
Copy link
Contributor

Myrkwid commented Mar 8, 2023

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.

@Datseris
Copy link
Member

Datseris commented Mar 8, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Easy issue good for newcomers help wanted The developers need some help here! project-setup Related to the functionality "Project setup"
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants