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
GitHub's advice and roadmap:
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) andcore.mainBranch(which is now configured byinit_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.
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.