libvcs.cmd.git

Use Git when you need direct access to git(1) from Python, with typed helpers for common subcommands and an escape hatch to run raw git arguments.

Compare to: fabtools.git, salt.modules.git, ansible.builtin.git

Managers and Commands

libvcs provides Managers and Commands for git subcommands:

  • Managers (git.branches, git.tags, etc.) let you traverse repository entities intuitively with ORM-like filtering via QueryList

  • Commands are contextual ways to run git commands against a specific target entity

See Traversing Git Repos for the full guide.

Git instance
├── branches: GitBranchManager
│   ├── ls() -> QueryList[GitBranchCmd]
│   ├── get() -> GitBranchCmd
│   └── create()
├── tags: GitTagManager
├── remotes: GitRemoteManager
├── stashes: GitStashManager
├── worktrees: GitWorktreeManager
├── notes: GitNotesManager
├── submodules: GitSubmoduleManager
└── reflog: GitReflogManager

Quick Example

List branches, rename one through its Cmd object, and manage tags:

>>> from libvcs.cmd.git import Git
>>> git = Git(path=example_git_repo.path)
>>> branches = git.branches.ls()
>>> len(branches) >= 1
True
>>> git.branches.create(branch='old-name')
''
>>> branch = git.branches.get(branch_name='old-name')
>>> branch.rename('new-name')
''
>>> git.tags.create(name='v1.0.0', message='Release 1.0')
''
>>> tag = git.tags.get(tag_name='v1.0.0')
>>> tag.delete()
"Deleted tag 'v1.0.0' ..."

Run git commands directly against a local git repo.

libvcs.cmd.git._filter_flags(value, *, allow_auto, combine_multiple=False)
function[source]
function[source]
libvcs.cmd.git._filter_flags(value, *, allow_auto, combine_multiple=False)
Parameters:
Return type:

list[str]

class libvcs.cmd.git.GitSubmoduleData
class libvcs.cmd.git.GitSubmoduleData

Bases: TypedDict

Structured submodule data returned by _ls().

exception libvcs.cmd.git.InvalidBuildOptions
exception[source]
exception[source]
exception libvcs.cmd.git.InvalidBuildOptions

Bases: ValueError

Raised when a git version output is in an unexpected format.

>>> InvalidBuildOptions("...")
InvalidBuildOptions('Unexpected git version output format: ...')
class libvcs.cmd.git.GitVersionInfo
class libvcs.cmd.git.GitVersionInfo

Bases: object

Information about the git version.

class libvcs.cmd.git.Git
class libvcs.cmd.git.Git

Bases: object

Run commands directly on a git repository.