Skip to main content

Branch management

The Python SDK provides multiple methods to manage the branches in an Infrahub instance.

Get a single branch

from infrahub_sdk import InfrahubClient
client = InfrahubClient()
branch = await client.branch.get(branch_name="main")

Get all the branches

from asyncio import run as aiorun

from rich import print as rprint

from infrahub_sdk import InfrahubClient


async def main():
client = InfrahubClient(address="http://localhost:8000")
branches = await client.branch.all()
rprint(branches)


if __name__ == "__main__":
aiorun(main())

Create a branch

from asyncio import run as aiorun

from infrahub_sdk import InfrahubClient


async def main():
client = InfrahubClient(address="http://localhost:8000")
await client.branch.create(branch_name="new-branch", description="description", sync_with_git=False)
print("New branch created")


if __name__ == "__main__":
aiorun(main())

Rebase a branch

from asyncio import run as aiorun

from infrahub_sdk import InfrahubClient


async def main():
client = InfrahubClient(address="http://localhost:8000")
await client.branch.rebase(branch_name="new-branch")


if __name__ == "__main__":
aiorun(main())

Merge a branch

from asyncio import run as aiorun

from infrahub_sdk import InfrahubClient


async def main():
client = InfrahubClient(address="http://localhost:8000")
await client.branch.merge(branch_name="new-branch")


if __name__ == "__main__":
aiorun(main())

Delete a branch

from infrahub_sdk import InfrahubClient
client = InfrahubClient()
await client.branch.delete(branch_name="new-branch")

Generating a diff for a branch

from infrahub_sdk import InfrahubClient
client = await InfrahubClient()
diff = await client.branch.diff_data(branch_name="new-branch")