Deployment
Deploy workflows from your Git repository to your n8n instance.
Deploy Command
n8n-gitops deploy [options]
Basic Usage
Deploy from Working Tree
Deploy workflows from your current working directory:
n8n-gitops deploy
Deploy from Git Reference
Deploy workflows from a specific Git tag, branch, or commit:
# Deploy from a tag
n8n-gitops deploy --git-ref v1.0.0
# Deploy from a branch
n8n-gitops deploy --git-ref main
# Deploy from a commit
n8n-gitops deploy --git-ref abc123def
This reads workflow files, scripts, and manifests directly from Git history using git show - no checkout required.
Dry Run
Preview what would be deployed without making changes:
n8n-gitops deploy --dry-run
Options
--git-ref <ref>
Deploy from a specific Git reference (tag, branch, or commit).
n8n-gitops deploy --git-ref v1.0.0
--dry-run
Show deployment plan without making changes.
n8n-gitops deploy --dry-run
Output:
Deployment plan:
+ CREATE: New Workflow
⟳ REPLACE: Existing Workflow
✓ Include: scripts/existing/process.py
[DRY RUN] No changes made
--backup
Backup old workflows by renaming them with a timestamp before replacing:
n8n-gitops deploy --backup
Behavior:
- Old workflow is renamed to
[BKP 2025-01-15 14:30:00] Workflow Name - New workflow is created with the original name
- Old workflow remains in n8n (deactivated)
--prune
Delete workflows in n8n that are not in the manifest:
n8n-gitops deploy --prune
Warning: This will permanently delete workflows. Use with caution.
Deployment Process
1. Load and Validate
- Loads authentication credentials
- Creates snapshot from Git ref (or working tree)
- Loads manifest from
n8n/manifests/workflows.yaml - Validates workflow files and include directives
2. Fetch Remote State
- Connects to n8n API
- Lists all remote workflows
- Creates name-to-ID mapping
3. Plan Deployment
For each workflow in manifest:
- CREATE: Workflow doesn't exist in n8n
- REPLACE: Workflow exists, will be deleted and recreated
The deployment plan is displayed before execution (unless --dry-run).
4. Execute Deployment
For each workflow:
-
Render workflow:
- Load workflow JSON
- Resolve
@@n8n-gitops:includedirectives - Inject code from script files
- Remove read-only fields
-
Create or Replace:
- CREATE: Create new workflow via API
- REPLACE:
- With
--backup: Rename old → Create new - Without
--backup: Delete old → Create new
- With
-
Set Active State:
- Call
/api/v1/workflows/{id}/activateifactive: true - Call
/api/v1/workflows/{id}/deactivateifactive: false
- Call
5. Prune (Optional)
If --prune is specified, delete workflows in n8n that are not in the manifest.
Deployment Strategies
Replace Strategy (Default)
The default strategy deletes old workflows and creates new ones:
n8n-gitops deploy
Pros:
- Clean slate for each deployment
- Guaranteed consistency with Git state
- No merge conflicts
Cons:
- Workflow ID changes
- Execution history is lost
- Webhooks URLs change
Replace with Backup
Keep old workflows as backups:
n8n-gitops deploy --backup
Pros:
- Can recover if deployment goes wrong
- Execution history preserved in backup
Cons:
- Accumulates backup workflows over time
- Need to manually clean up old backups
Example Output
Deploying workflows from /path/to/project
Using git ref: v1.0.0
Target: https://n8n.example.com
Loaded manifest: 2 workflow(s)
Fetching remote workflows...
Found 1 remote workflow(s)
Deployment plan:
+ CREATE: New Payment Workflow
⟳ REPLACE: Existing Data Sync
✓ Include: scripts/Existing_Data_Sync/process.py
Executing deployment...
Creating: New Payment Workflow...
✓ Created with ID: abc123
Activating workflow...
✓ Activated
Replacing: Existing Data Sync...
Deleting old workflow...
✓ Old workflow deleted
Creating new workflow...
✓ Created with ID: def456
Deactivating workflow...
✓ Deactivated
✓ Deployment successful!
Active State Management
The deployment process manages workflow active state based on the manifest:
# n8n/manifests/workflows.yaml
workflows:
- name: "Production Workflow"
file: "workflows/production.json"
active: true # Will be activated after deployment
- name: "Test Workflow"
file: "workflows/test.json"
active: false # Will be deactivated after deployment
After creating/replacing a workflow:
- If
active: true→ POST to/api/v1/workflows/{id}/activate - If
active: false→ POST to/api/v1/workflows/{id}/deactivate
Include Directives
Workflows with include directives are automatically rendered during deployment:
{
"nodes": [
{
"parameters": {
"pythonCode": "@@n8n-gitops:include scripts/payment/process.py"
}
}
]
}
The include directive is resolved and replaced with the actual code before deployment.
See Code Externalization for details.
Rollback Command
The rollback command is an alias for deploy --git-ref:
# These are equivalent:
n8n-gitops rollback --git-ref v0.9.0
n8n-gitops deploy --git-ref v0.9.0
Error Handling
Validation Errors
If workflow validation fails:
Error rendering workflow Payment Processing: Include path outside scripts/
Fix the issue in your repository and try again.
API Errors
If the n8n API returns an error:
✗ Error: API request failed: POST /api/v1/workflows -> HTTP 400:
{"message": "Additional properties are not allowed"}
💡 Tip: The workflow file may contain n8n-managed fields.
Run 'n8n-gitops validate' to check for problematic fields.
Re-export the workflow to get a clean version:
n8n-gitops export
Common fixes:
- Re-export the workflow:
n8n-gitops export - Run validation:
n8n-gitops validate - Check API credentials
Authentication
The deploy command requires authentication. See Authentication for details.
See Also
- Export - Export workflows from n8n
- Manifest File - Understand the manifest format
- Code Externalization - Learn about include directives
- Validation - Validate before deployment