ekchom
ekchom

Reputation: 148

create "master" first branch without commit using libgit2

On shell I can do something below using bash git

mkdir -p /tmp/REPO/ROOT && pushd /tmp/REPO/ROOT && git init && git checkout -b anyName

As summary above init a local git repo at given path and create a branch "anyName". Please note that there is no commit history in the repo yet.

However in libgit2, to create a branch I need to have commit as API is as below https://libgit2.org/libgit2/#HEAD/group/branch/git_branch_create

int git_branch_create(git_reference **out, git_repository *repo, const char *branch_name, const git_commit *target, int force);

It needs a git_commit , on which branch will be based.

Is there a way to achieve something similar that what bash/cmd git cli support?

Upvotes: 0

Views: 81

Answers (1)

lrm29
lrm29

Reputation: 498

I haven't tried it but I think you want to set initial_head when you call git_repository_init_ext:

https://libgit2.org/libgit2/#HEAD/type/git_repository_init_options

Upvotes: 1

Related Questions