vcti-git
Git repository operations for VCollab applications
Overview
vcti-git provides one class, Repository, with a small API for the Git
operations an application most often automates: clone, commit, manage
remotes, fetch, fast-forward pull and push. Repository is a thin façade
over one of three interchangeable backends — pygit2, GitPython or dulwich —
selected by argument, by environment variable or by auto-detection, so the
same code runs where a git binary is installed and where it is not.
Every failure is raised as GitError or one of its two subclasses,
whichever backend is active, so a caller never imports a backend's own
exception types. It is a focused wrapper rather than a full Git client:
branch management, history, merges and authentication are outside it.
Installation
The backends are optional extras, and at least one is needed:
pip install "vcti-git[pygit2]" # libgit2 wheel; no git binary needed
pip install "vcti-git[gitpython]" # drives the system git binary
pip install "vcti-git[dulwich]" # pure Python; no native dependencies
Installed without an extra, the package imports, but constructing a
Repository raises GitError with these instructions.
In requirements.txt
vcti-git[pygit2]>=2.0.0
In pyproject.toml dependencies
dependencies = [
"vcti-git[pygit2]>=2.0.0",
]
Quick Start
The snippets below assume three names of your own: remote_url, the URL
of a repository to clone; clone_path, where to clone it; and
repo_path, an existing clone whose origin you can push to.
Clone a repository
from vcti.git import Repository
repo = Repository(clone_path)
repo.clone(remote_url)
print(repo.is_valid()) # True
repo.close()
clone(url, overwrite=True) replaces an existing clone. It refuses a
directory that is neither empty nor a Git repository, and restores the
original if the new clone fails.
Commit and push
with Repository(repo_path) as repo:
(repo.path / "notes.txt").write_text("hello\n")
repo.commit("Add notes", add_all=True) # stage everything, then commit
repo.push() # the checked-out branch, to origin
Without add_all=True, commit() commits what is already staged. Used
as a context manager, Repository releases its handle on the underlying
library when the block ends; repo.close() does the same explicitly.
Fetch and pull
with Repository(repo_path) as repo:
repo.fetch("origin", prune=True, tags=True)
# Fetch, then fast-forward the checked-out branch. Never merges: if
# the branch has diverged from the remote, GitError is raised.
repo.pull()
Manage remotes
with Repository(repo_path) as repo:
repo.add_remote("upstream", remote_url) # registers it; does not fetch
print(sorted(repo.list_remotes())) # ['origin', 'upstream']
repo.remove_remote("upstream")
Select a backend
repo = Repository(repo_path) # auto-detect
print(repo.backend_name)
repo = Repository(repo_path, backend="dulwich") # explicit
Auto-detection prefers pygit2, then gitpython, then dulwich, among
those installed. The VCTI_GIT_BACKEND environment variable overrides
auto-detection without a code change, and the backend= argument
overrides both:
VCTI_GIT_BACKEND=dulwich python my-app.py
Handle errors
Every exception Repository raises derives from GitError. Catch the
subclass you can act on, or the base class for everything:
from vcti.git import GitError, RemoteError, RepositoryError
try:
with Repository(repo_path) as repo:
repo.fetch("no-such-remote")
except RemoteError as e:
print(f"Remote operation failed: {e}")
except RepositoryError as e:
print(f"Not a usable repository: {e}")
except GitError as e:
print(f"Other git failure: {e}")
Messages start with the backend's tag — [pygit2], [gitpython] or
[dulwich] — so a log line says which backend produced it.
Public API
| Member | Purpose |
|---|---|
Repository(path, *, backend=None) |
A handle on the repository at path. backend=None consults VCTI_GIT_BACKEND, then auto-detects. |
.path |
The resolved, absolute local path |
.backend_name |
The backend in use |
.is_valid() |
Whether path is itself a Git repository |
.clone(url, *, overwrite=False) |
Clone url into path |
.commit(message, *, add_all=False) |
Commit what is staged; optionally stage everything first |
.list_remotes() |
The remotes, as {name: url} |
.add_remote(name, url) |
Register a remote, without fetching |
.remove_remote(name) |
Remove a remote |
.fetch(remote="origin", *, prune=False, tags=False) |
Fetch from a remote |
.pull(remote="origin", branch=None) |
Fetch and fast-forward the checked-out branch |
.push(remote="origin", branch=None, *, force=False) |
Push a branch; the checked-out one by default |
.close() |
Release the backend's handle; also done on leaving a with block |
GitError |
Base class of every error raised |
RepositoryError |
The path is not a usable repository, or not safe to overwrite |
RemoteError |
A remote operation failed: clone, fetch, pull, push, remote configuration |
Backends
| Backend | Extra | Needs | Notes |
|---|---|---|---|
pygit2 |
vcti-git[pygit2] |
libgit2, shipped in the wheel | Preferred by auto-detection. Suits slim container images. commit() requires user.name and user.email in the git config. |
gitpython |
vcti-git[gitpython] |
a git binary on PATH |
Uses the system git's credential helpers. |
dulwich |
vcti-git[dulwich] |
nothing native | Pure Python: slower, and the most portable. |
A Repository instance is not thread-safe; use one per thread.
Dependencies
None required. Each backend is an optional extra and brings one library: pygit2, GitPython or dulwich.
Documentation
| If you want to… | Read |
|---|---|
| Get started using the package | Quick Start above |
| See practical usage and the pitfalls to avoid | docs/patterns.md |
| Look up an error message and what to do about it | docs/errors.md |
| Understand the design decisions and what is out of scope | docs/design.md |
| Navigate and understand the source | docs/source-guide.md |
Metadata
Release files for vcti-git 2.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| vcti_git-2.0.0.tar.gz | 39.3 kB | With provenance | Details for vcti_git-2.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| vcti_git-2.0.0-py3-none-any.whl | Python 3 | none | any | Details for vcti_git-2.0.0-py3-none-any.whl |
Total release size: 61.1 kB
Release files / vcti_git-2.0.0.tar.gz
| Download URL | vcti_git-2.0.0.tar.gz |
|---|---|
| Size | 39.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
18cfe5b60d6a338ea0cce80f974cc099b9f8aab7673cb51425e0a6b2ad34d580
|
|
BLAKE2b-256 checksum How to use checksums |
e68bed4e7320f1a9527af1821d31b6712dcffd3c01d46e9cf2db3d44a31c45ee
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 27, 2026.
Transparency logRelease files / vcti_git-2.0.0-py3-none-any.whl
| Download URL | vcti_git-2.0.0-py3-none-any.whl |
|---|---|
| Size | 21.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
a0137076bb88e543acf1733d47a87e69e112aa278e9ac466dca9842fd2c75432
|
|
BLAKE2b-256 checksum How to use checksums |
ac20188b36b17cec56131040706b0a98fae2eab37a2dba1fc1d3781b2ff52f43
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 27, 2026.
Transparency logSecurity for vcti-git 2.0.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for vcti_git-2.0.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 27, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.