References

Example:

>>> all_refs = repo.listall_references()
>>> master_ref = repo.lookup_reference("refs/heads/master")
>>> commit = master_ref.get_object() # or repo[master_ref.target]

The HEAD

Example. These two lines are equivalent:

>>> head = repo.lookup_reference('HEAD').resolve()
>>> head = repo.head

Branches

Branches inherit from References, and additionally provide spetialized accessors for some unique features.

Example:

>>> local_branches = repo.listall_branches()
>>> # equivalent to
>>> local_branches = repo.listall_branches(pygit2.GIT_BRANCH_LOCAL)

>>> remote_branches = repo.listall_branches(pygit2.GIT_BRANCH_REMOTE)

>>> all_branches = repo.listall_branches(pygit2.GIT_BRANCH_REMOTE |
                                         pygit2.GIT_BRANCH_LOCAL)

>>> master_branch = repo.lookup_branch('master')
>>> # equivalent to
>>> master_branch = repo.lookup_branch('master',
                                       pygit2.GIT_BRANCH_LOCAL)

>>> remote_branch = repo.lookup_branch('upstream/feature',
                                       pygit2.GIT_BRANCH_REMOTE)

The reference log

Example:

>>> head = repo.lookup_reference('refs/heads/master')
>>> for entry in head.log():
...     print(entry.message)

Table Of Contents

Previous topic

Git Objects

Next topic

Revision parsing

This Page