How to change branch name using `LibGit2`?

sorry, not sure which category suits best

I am using LibGit2 to create a new git repository inside a package. I am doing something like:

        repo = LibGit2.init(path)
        sig = LibGit2.Signature("DrWatson", "no@mail", round(Int, time()), 0)
        LibGit2.commit(repo, "Initial commit"; author=sig, committer=sig)

to initialize the repository on a given path. Now, I want to ensure the default branch of this repository is always main because of some subsequent steps.

How do I do it without expecting git to be accessable from the command line, i.e., without doing run(git -m ...)?


default = LibGit2.branch(repo)
ERROR: GitError(Code:EUNBORNBRANCH, Class:Reference, reference 'refs/heads/master' not found)

already errors. So I guess a secondary question is how do I even get the name of the default branch using LibGit2?

One option is to use Git.jl which uses JLLs to ship command line git. I don’t know how to do it with LibGit2.

How do you handle paths in Git.jl? One reason I decided to go with LibGit2.jl is because it creates this “git repo” object, and what is my pwd() doesn’t matter. I suspect that with Git.jl I would have to change path to the path I create the init(path), right?

Isn’t this unecessary? I thought it is guaranteed that there is git installed if Julia is installed, because my understanding of the package system is that it does not work without git. That’s what LibGit2 does, it interfaces that git installation I thought.

LibGit2 is a git implementation, not an interface to one, IIUC. My point is you can use Git.jl to use a command-line one, so you can use usual commands like the first example from the readme:

julia> using Git

julia> run(`$(git()) clone`)

By using Git.jl you don’t have to assume the user has command-line git installed, but you can use the familiar command line interface.