Work with branches
Branches in Infrahub provide isolated workspaces where you can make changes without affecting the main branch. This guide shows you how to create, manage, and delete branches using the GraphQL API, UI, or SDK.Prerequisites
Before working with branches, ensure you have:- Access to an Infrahub instance
- Appropriate permissions to create and manage branches
- GraphQL API access or SDK installed (if using programmatic methods)
Create a branch
Branches are always created from themain branch. You can create a branch with data-only changes or one that synchronizes with Git repositories.
Using GraphQL
Create a branch using theBranchCreate mutation:
name(required): Branch name following Git ref standards (3-250 characters)description(optional): Human-readable description of the branch purposesync_with_git(optional, default:true): Whether to synchronize with Git repositoriesorigin_branch(optional): Must bemain(currently the only supported value)branched_from(optional): Timestamp to branch from (defaults to current time)
Using the Python SDK
Branch naming rules
Branch names must follow Git ref standards and cannot contain:/.(path component starting with dot)..(double dots)- Leading
/(cannot start with slash) //(double slashes)@{(at-brace sequence)\\(backslashes)- Disallowed ASCII characters (control characters,
~^:?*[]) .locksuffix- Trailing
/or.
__GLOBAL__.
Valid names:
feature-add-devicesfix/datacenter-connectivityexperiment_new_schema
feature..fix(contains..)fix/(ends with/)branch.lock(ends with.lock)/feature(starts with/)
View branch details
Retrieve information about a specific branch or list all branches.Query a single branch
List all branches
Using the Python SDK
Update a branch
Update the description of an existing branch:description field can be updated after branch creation. The branch name and other properties are immutable.
Delete a branch
Delete a branch when it’s no longer needed. You cannot delete the default branch (main) or the global branch.
Using GraphQL
wait_until_completion(optional, default:true): Whether to wait for deletion to complete
wait_until_completion is false, the mutation returns a task ID:
Using the Python SDK
Work with data-only branches
Data-only branches (sync_with_git: false) isolate changes to Infrahub without affecting Git repositories. These are ideal for data corrections or updates that don’t require code changes.
- Do not create corresponding Git branches
- Are not merged to Git repositories
- Are ideal for quick data fixes and updates
- Still maintain full version control and history
Verify branch creation
After creating a branch, verify it exists and has the expected properties:Branch status values
Branches can have the following status values:- OPEN: Branch is active and ready for changes
- NEED_REBASE: Branch needs to be rebased with the main branch
- NEED_UPGRADE_REBASE: Branch requires migration before it can be used
- DELETING: Branch is being deleted
backend/infrahub/core/branch/models.py:33.
Common patterns
Create a branch for a specific feature
Create a branch for experimentation
Related resources
- Proposed changes - Review and merge branch changes
- Merge conflicts - Resolve conflicts between branches
- Time travel queries - Query historical data
- Branching topic - Understand how branching works in Infrahub