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.

class libvcs.cmd.git.Git
ΒΆ
class libvcs.cmd.git.Git
ΒΆ

Bases: object

Run commands directly on a git repository.