Repository Types
Infrahub supports two types of Git repositories:Standard Repository (Read-Write)
Full bidirectional integration with branch synchronization:- Automatically syncs branches from Git to Infrahub
- Creates new Infrahub branches when Git branches are detected
- Supports merge operations from Infrahub to Git
- Imports objects (schemas, generators, transformations) on sync
- Validates branch structure before sync
active: Repository is fully operational and syncingstaging: Repository is being prepared for activation
Read-Only Repository
One-way sync from a specific Git ref:- Tracks a single ref (branch/tag/commit)
- Pulls updates from the remote ref
- Cannot push changes back to Git
- Useful for consuming external schemas or libraries
Adding a Repository
Using the UI
- Navigate to Resources > Repositories
- Click Add Repository
- Configure:
- Name: Unique identifier
- Location: Git URL (https:// or ssh://)
- Default Branch: Main branch name
- Credential: Optional authentication
Using the SDK
Repository Synchronization
Automatic Sync
Repositories sync automatically every minute via thegit_repositories_sync workflow:
Manual Sync
Trigger sync via GraphQL mutation:Sync Workflow
- Fetch: Pull latest changes from remote
- Compare: Identify new and updated branches
- Validate: Check branch structure matches patterns
- Create Branches: Create Infrahub branches for new Git branches
- Import Objects: Load schemas, generators, checks from files
- Update Commit: Store latest commit SHA in database
Branch Mapping
Infrahub maps Git branches to Infrahub branches:- Git branch
main→ Infrahub branchmain - Git branch
feature/new-schema→ Infrahub branchfeature/new-schema - Branches are created automatically on first sync
- Worktrees manage per-branch checkouts
Repository Operations
Creating Branches
When you create a branch in Infrahub, it’s created in all active repositories:Merging Branches
Merge operations sync to Git repositories:File Import
Repositories can contain:Schemas
.schema/directory- YAML files defining node types
- Auto-loaded on sync
Generators
- Python files with generator classes
- Registered via
CoreGeneratorobjects - Executed to create nodes
Transformations
- Jinja2 templates or Python transforms
- Used by artifacts and webhooks
- Referenced by
CoreTransformJinja2orCoreTransformPython
Checks
- Python classes for validation
- Executed during proposed change validation
- Referenced by
CoreCheckDefinition
Import Process
Commit Tracking
Each repository tracks the commit SHA per branch:- Stored in the
commitattribute - Updated on successful sync
- Used to detect changes between syncs
- Enables diff operations between commits
Worktrees
Infrahub uses Git worktrees for branch isolation:- Multiple branches checked out simultaneously
- Isolated environments for transforms/checks
- No branch switching overhead
Repository Models
GitRepositoryAdd
GitRepositoryMerge
Authentication
Repositories support multiple authentication methods:SSH Keys
- Configure SSH credential in Infrahub
- Link to repository via
credentialrelationship - Private key stored securely
HTTPS with Tokens
- Personal access tokens
- Stored in credential objects
- Injected into Git URLs
Credential Objects
Create via SDK:Conflict Detection
Infrahub checks for merge conflicts during proposed change validation:Best Practices
Repository Structure
Performance
- Use read-only repositories for reference data
- Limit branch creation to necessary branches
- Keep repositories focused (don’t store large binaries)
- Use
.gitignoreto exclude generated files
Security
- Use SSH keys for private repositories
- Rotate credentials regularly
- Audit repository access logs
- Validate schemas before import
Troubleshooting
Repository Not Syncing
- Check repository operational status:
operational_status - Verify credential is valid
- Review sync logs in workflow runs
- Ensure repository is reachable from Infrahub server
Import Failures
- Validate schema files locally first
- Check Python syntax in generator/check files
- Review error messages in import logs
- Verify file paths are correct
Merge Conflicts
- Use conflict detection check
- Resolve conflicts in Git
- Re-sync repository
- Retry proposed change merge