libgit2

git_reference_create

Version:

Create a new direct reference.

A direct reference (also called an object id reference) refers directly to a specific object id (a.k.a. OID or SHA) in the repository. The id permanently refers to the object (although the reference itself can be moved). For example, in libgit2 the direct ref "refs/tags/v0.17.0" refers to OID 5b9fac39d8a76b9139667c26a63e6b3f204b3977.

The direct reference will be created in the repository and written to the disk. The generated reference object must be freed by the user.

Valid reference names must follow one of two patterns:

  1. Top-level names must contain only capital letters and underscores, and must begin and end with a letter. (e.g. "HEAD", "ORIG_HEAD").
  2. Names prefixed with "refs/" can be almost anything. You must avoid the characters '~', '^', ':', '
    ', '?', '[', and '*', and the sequences ".." and "@{" which have special meaning to revparse.

This function will return an error if a reference already exists with the given name unless force is true, in which case it will be overwritten.

Signature

int git_reference_create(git_reference **out, git_repository *repo, const char *name, const git_oid *id, int force);

Parameters

In
out

Pointer to the newly created reference

In
repo

Repository where that reference will live

const char *
In
name

The name of the reference

In
id

The object id pointed to by the reference.

int
In
force

Overwrite existing references

Returns

int

0 on success, GIT_EEXISTS, GIT_EINVALIDSPEC or an error code

Versions