How to control the name of the default branch from Repository.Init?

Open
#1,964 6 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
45/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Quiet
Tech stack
csharp, git
Domain
tooling

Research direction

Start by reviewing Repository.Init(string) and the issue's discussion of .git/HEAD and first-commit branch creation. Determine whether the existing API exposes a way to select the initial branch name; done means a new repository can consistently use the requested default branch across machines, with coverage for the initialization behavior.

Written by the indexing model from the issue text.

Description

I have automated test failures due to Repository.Init(string) creating repos with main as the default branch name instead of master. How can I control the name of the default branch for a new repository so that my tests pass consistently across machines?

I tried using libgit2sharp APIs to create a new branch and deleting the old, but in fact on a brand new repository, there is no branch and no commit, so I guess the default branch is just the name that HEAD will use for a new branch once the first commit is authored. It appears this is stored in .git/HEAD. Is there an API to help us rewrite that file, perhaps?

Dominant language
C#
Stars
3.5k
Forks
925
PR merge metrics
No merged PRs in 30d

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from libgit2/libgit2sharp

All issues in libgit2/libgit2sharp

Similar issues

More C# issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.