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, const git_signature *signature, const char *log_message);

Parameters

In
out

Pointer where to store the underlying reference.

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.

In
signature

The identity that will used to populate the reflog entry

const char *
In
log_message

The one line long message to be appended to the reflog. If NULL, the default is "Branch: created"; if you want something more useful, provide a message.

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