References

Example:

>>> all_refs = list(repo.references)

>>> master_ref = repo.references["refs/heads/master"]
>>> commit = master_ref.peel() # or repo[master_ref.target]

# Create a reference
>>> ref = repo.references.create('refs/tags/version1', LAST_COMMIT)

# Delete a reference
>>> repo.references.delete('refs/tags/version1')

# Pack loose references
>>> repo.references.compress()

Functions

Check if the passed string is a valid reference name.

Example:

>>> from pygit2 import reference_is_valid_name
>>> reference_is_valid_name("refs/heads/master")
True
>>> reference_is_valid_name("HEAD")
True
>>> reference_is_valid_name("refs/heads/..")
False

The Reference type

The HEAD

Example. These two lines are equivalent:

>>> head = repo.references['HEAD'].resolve()
>>> head = repo.head

The reference log

Example:

>>> head = repo.references.get('refs/heads/master')  # Returns None if not found
>>> # Almost equivalent to
>>> head = repo.references['refs/heads/master']  # Raises KeyError if not found
>>> for entry in head.log():
...     print(entry.message)

Notes

The Note type