Tips > Building Workflows

Version Your Workflows Using Workflow History or Git

n8n makes it easy to modify workflows in-place, but without versioning, a bad edit can destroy a working automation with no way to roll back.

TipAdvanced2 min read

n8n makes it easy to modify workflows in-place, but without versioning, a bad edit can destroy a working automation with no way to roll back. n8n provides built-in workflow history (execution-linked snapshots) and, for advanced teams, Git-based version control via the n8n API.

Real-world example: Setting up Git-based workflow version control using n8n's REST API and a scheduled backup workflow.

Automated backup workflow that runs daily:

[Schedule Trigger: Daily 2 AM]
    → [HTTP Request: GET /api/v1/workflows]
    → [Code: Process each workflow]
    → [HTTP Request: Commit to Git repo]
```text
Code node to export all workflows:

```javascript
const workflows = $input.all();
const exports = [];

for (const wf of workflows) {
  const workflow = wf.json;

  // Sanitize: remove execution data and credential secrets
  const sanitized = {
    id: workflow.id,
    name: workflow.name,
    nodes: workflow.nodes,
    connections: workflow.connections,
    settings: workflow.settings,
    tags: workflow.tags,
    // Exclude: staticData, credentials (contain secrets)
  };

  exports.push({
    json: {
      filename: `workflows/${workflow.id}_${workflow.name.replace(/[^a-zA-Z0-9]/g, '_')}.json`,
      content: JSON.stringify(sanitized, null, 2)
    }
  });
}

return exports;
```text
For teams using n8n's built-in history (available in newer versions):

```text
Workflow History features:
- Automatic snapshots on every save
- Compare versions side-by-side
- Restore any previous version with one click
- History retention configurable (default: 30 days)

Access: Workflow canvas → "..." menu → "Workflow History"
```text
> **Warning: Credentials Are Not Versioned**
>
> Workflow exports (JSON) intentionally exclude credential secrets. After restoring a workflow from backup, you must re-select the correct credentials for each node. Document which credentials each workflow uses in a Sticky Note.

Git-based versioning with a naming convention for commit messages:

```text
Convention: [workflow-id] [action] [description]

Examples:
  [wf-42] update Added retry logic to payment node
  [wf-42] rollback Reverted to pre-migration version
  [wf-15] create New lead scoring workflow
  [wf-15] deprecate Replaced by wf-67
```text
Versioning is insurance. The cost is near zero and the value is infinite the first time you need to roll back a broken change.

**Related:** [Always Set an Error Workflow on Every Production Workflow](../error-handling-and-reliability/01-always-set-an-error-workflow-on-every-production-workflow.md) | [Use "Pin Data" to Freeze Node Output](../testing-and-debugging/01-use-pin-data-to-freeze-node-output.md)

Want this running in your stack?

I build production n8n and Cloudflare automation for teams — the same engineering behind HarperFlow. Fixed-price, escrow-protected, US-based.