Usethis: Honor a default Git branch that is not `master`

Created on 13 Jun 2020  路  7Comments  路  Source: r-lib/usethis

In the course of the git2r --> gert refactor, analyze how we can detect repo's default branch, i.e. don't assume or hard-wire it to master. Can probably be similar to how we figure out / respect user's preference for Git protocol (SSH vs HTTPS) or other usethis options.

Example of the mechanics of renaming master to main:

https://www.hanselman.com/blog/EasilyRenameYourGitDefaultBranchFromMasterToMain.aspx

git

Most helpful comment

Because of the above, I think usethis should NOT implement its own solution but should fall in line with the above (e.g. the new git config settings), as it rolls out.

All 7 comments

GitHub's advice and roadmap:

https://github.com/github/renaming

Git project's statement:

https://sfconservancy.org/news/2020/jun/23/gitbranchname/

Code changes (unclear to me if this is a done deal or still just a proposal):

https://lore.kernel.org/git/[email protected]/

Most relevant excerpt for me:

There are now two config settings: init.defaultBranch (defining the branch name to use when initializing new repositories) and core.mainBranch (which is now configured by init_db(), declaring what the name of the main branch is in this repository).

Because of the above, I think usethis should NOT implement its own solution but should fall in line with the above (e.g. the new git config settings), as it rolls out.

Yet another set of instructions for changing default branch from master to something else. The advice here re: what other collaborators should do is the cleanest I've seen. Just want to save this link somewhere.

https://levelup.gitconnected.com/how-to-change-git-default-branch-from-master-3933afab08f9

Best thread I've found yet on how to detect what the default branch on a remote is:

https://stackoverflow.com/questions/28666357/git-how-to-get-default-branch

You can dig this info out of the result of git remote show [your_remote].

But so far I see no way to achieve this with gert.

Update: discussed with @jeroen and we have the new gert::git_remote_ls()

I've also updated an issue in libgit2: https://github.com/libgit2/libgit2/issues/5646

But for now, there is no reliable offline method, and you need gert::git_remote_ls() to see the default branch on the server.

There's also an open PR on libgit2 to match Git's new support for init.defaultBranch:

https://github.com/libgit2/libgit2/pull/5581

This is a good thing to upvote. It is helpful for all of us if repos created by libgit2 "look" the same as those created with command line Git.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

maxheld83 picture maxheld83  路  3Comments

aosmith16 picture aosmith16  路  5Comments

Jadamso picture Jadamso  路  3Comments

jennybc picture jennybc  路  4Comments

hadley picture hadley  路  5Comments