branch

For git-branch(1).

Overview

Manage git branches using GitBranchManager (collection-level) and GitBranchCmd (per-branch operations).

Examples

List branches — local by default, remote with remotes=True:

>>> from libvcs.cmd.git import Git
>>> git = Git(path=example_git_repo.path)
>>> branches = git.branches.ls()
>>> len(branches) >= 1
True
>>> remote_branches = git.branches.ls(remotes=True)
>>> isinstance(remote_branches, list)
True

Create a branch, then look it up:

>>> from libvcs.cmd.git import Git
>>> git = Git(path=example_git_repo.path)
>>> git.branches.create(branch='feature-branch')
''
>>> branch = git.branches.get(branch_name='feature-branch')
>>> branch.branch_name
'feature-branch'

Rename or delete a branch through its Cmd object:

>>> from libvcs.cmd.git import Git
>>> git = Git(path=example_git_repo.path)
>>> git.branches.create(branch='old-name')
''
>>> branch = git.branches.get(branch_name='old-name')
>>> branch.rename('new-feature')
''
>>> renamed = git.branches.get(branch_name='new-feature')
>>> renamed.delete()
'Deleted branch new-feature ...'

API Reference

class libvcs.cmd.git.GitBranchManager
class libvcs.cmd.git.GitBranchManager

Bases: object

Traverse and manage git branches with ORM-like filtering via QueryList.

class libvcs.cmd.git.GitBranchCmd
class libvcs.cmd.git.GitBranchCmd

Bases: object

Run git commands targeting a specific branch.