libgit2

git_branch_create

Version:

Create a new branch pointing at a target commit

A new direct reference will be created pointing to this target commit. If force is true and a reference already exists with the given name, it'll be replaced.

The returned reference must be freed by the user.

The branch name will be checked for validity. See git_tag_create() for rules about valid names.

Signature

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

Parameters

In
out

Pointer where to store the underlying reference.

In
repo

the repository to create the branch in.

const char *
In
branch_name

Name for the branch; this name is validated for consistency. It should also not conflict with an already existing branch name.

In
target

Commit to which this branch should point. This object must belong to the given repo.

int
In
force

Overwrite existing branch.

Returns

int

0, GIT_EINVALIDSPEC or an error code. A proper reference is written in the refs/heads namespace pointing to the provided target commit.

Versions