Everything starts either by creating a new repository, or by opening an existing one.
Contents
Creates a new Git repository in the given path.
If bare is True the repository will be bare, i.e. it will not have a working copy.
Example:
>>> from pygit2 import init_repository
>>> repo = init_repository('test') # Creates a non-bare repository
>>> repo = init_repository('test', bare=True) # Creates a bare repository
Clones a new Git repository from url in the given path.
bare indicates whether a bare git repository should be created.
remote_name is the name given to the “origin” remote. The default is “origin”.
checkout_branch gives the name of the branch to checkout. None means use the remote’s HEAD.
Returns a Repository class pointing to the newly cloned repository.
If you wish to use the repo, you need to do a checkout for one of the available branches, like this:
>>> repo = repo.clone_repository("url", "path")
>>> repo.checkout(branch) # i.e.: refs/heads/master
Example:
>>> from pygit2 import clone_repository
>>> repo_url = 'git://github.com/libgit2/pygit2.git'
>>> repo_path = '/path/to/create/repository'
>>> repo = clone_repository(repo_url, repo_path) # Clones a non-bare repository
>>> repo = clone_repository(repo_url, repo_path, bare=True) # Clones a bare repository
Look for a git repository and return its path.
The Repository constructor only takes one argument, the path of the repository to open.
Example:
>>> from pygit2 import Repository
>>> repo = Repository('pygit2/.git')
The API of the Repository class is quite large. Since this documentation is orgaized by features, the related bits are explained in the related chapters, for instance the pygit2.Repository.checkout() method are explained in the Checkout section.
Below there are some general attributes and methods:
The normalized path to the git repository.
The normalized path to the working directory of the repository. If the repository is bare, None will be returned.
Check if a repository is a bare repository.
Check if a repository is empty.
Read raw object data from the repository.
Write raw object data into the repository. First arg is the object type, the second one a buffer with data. Return the Oid of the created object.