In our previous lesson, we established a crucial principle for scalable automation: separating a workflow's logic from its environment-specific configuration. By parameterizing endpoints and credentials, you've prepared your workflows to be portable. Now, we will focus on the mechanics of that portability—how to export workflows from a development environment, place them under version control, and automatically deploy them to production, completing the CI/CD loop.
This lesson directly addresses your goal of integrating n8n into a professional development lifecycle. Your experience with CI/CD tools and Git will be central here, as we'll treat n8n workflows just like any other code artifact that needs to be versioned, reviewed, and deployed. The process we'll build today is the practical implementation of a robust governance model.

The Simplest Form of Portability: Workflows as JSON
At its core, every n8n workflow is a JSON object. This simple fact is the foundation of its portability. The most basic method of moving a workflow is to manually copy and paste this JSON data.
You can view a workflow's JSON by selecting all the nodes on the canvas (Ctrl+A or Cmd+A), copying them (Ctrl+C or Cmd+C), and pasting the content into a text editor. To import, you simply copy the JSON and paste it onto the canvas of another n8n instance. This method is surprisingly effective for quick, one-off transfers or for restoring a workflow from a backup.
How to auto-backup n8n workflows to GitHub
The video "How to auto-backup n8n workflows to GitHub" demonstrates this manual restoration process.
Watch the final segment starting from the restoration process, where a deleted workflow is restored by simply copying its JSON from a file in GitHub and pasting it onto the n8n canvas. This is the manual "import" process in its rawest form.
While simple, manual copy-pasting is error-prone and doesn't scale. It's a useful fallback, but for a real CI/CD process, you need automation.
Automating Export with a "Meta-Workflow"
One way to automate this process is to use n8n itself. You can create a "meta-workflow" whose job is to back up your other workflows. This approach typically involves three key steps:
- List Workflows: Use the
n8n APInode to connect to your own n8n instance and get a list of all your workflows. - Prepare Files: Process the JSON data for each workflow, perhaps converting it to a binary file with a descriptive name.
- Push to Git: Use the
GitHubnode to push these workflow files to a repository, creating a new commit.
The same video provides a full walkthrough of building such a workflow. It’s a powerful demonstration of how you can use n8n's own tools to manage your n8n environment. While this is a viable custom solution, n8n now offers a more deeply integrated feature for this purpose.
The Integrated Solution: n8n Source Control
For a robust, enterprise-grade CI/CD pipeline, n8n's built-in source control feature is the recommended approach. It directly connects an n8n instance to a Git repository, allowing you to push and pull workflows in a structured way that aligns with standard DevOps practices.
Tutorial - Create environments with source control - n8n Docs
This official n8n documentation provides a complete guide to setting up and using the source control feature. It's the blueprint for the process we're discussing.
First, understand the architectural choice by reading about the two main source control patterns. Your choice between a multi-branch or single-branch strategy will depend on your team's workflow and risk tolerance. Next, review the steps for setting up the repository and connecting your instances. This involves creating a deploy key in GitHub, which grants your n8n instances secure, programmatic access to the repository. This should be a familiar concept from your work with other CI/CD tools. Finally, read about the core mechanics: pushing work from development and pulling it to production. Notice that this process also handles credentials by pushing "stubs"—placeholders that you fill in on the target environment, reinforcing the principle of separating logic from configuration.
The manual push from dev and pull to prod is already a significant improvement. However, the true power of this integration comes from automating the final deployment step. This is where your CI/CD knowledge comes into play. The n8n documentation provides an example of a GitHub Action that automates the deployment.
This action is triggered on a push to the production branch. It then makes an API call to your production n8n instance, telling it to pull the latest changes from that same branch.
name: CI
on:
push:
branches: [ "production" ]
workflow_dispatch:
jobs:
run-pull:
runs-on: ubuntu-latest
steps:
- name: PULL
run: >
curl --location '${{ secrets.INSTANCE_URL }}/version-control/pull' --header
'Content-Type: application/json' --header 'X-N8N-API-KEY: ${{ secrets.INSTANCE_API_KEY }}'
This simple curl command, executed within a GitHub Action, is the final piece of the puzzle. It closes the loop, creating a true GitOps-style workflow for your n8n automations. You push code to Git, and the CI/CD system handles the rest, ensuring your production instance is always in sync with your main branch.
An Advanced Alternative: A Python-driven CLI
For teams that prefer a more code-centric, CLI-driven approach, the open-source community provides powerful alternatives. Given your proficiency in Python, the n8n-workflow-builder library is an excellent tool to be aware of.
This library allows you to manage your entire n8n environment from the command line, treating your workflows as configuration files within a larger project.
n8n Workflow Builder - Free Python Library | Matt Ferrante
This page introduces a Python library for managing n8n workflows programmatically.
Read the sections Why Use n8n Workflow Builder? and Features in Detail. This library allows you to define workflows in YAML and use CLI commands like n8n-workflow-builder push and n8n-workflow-builder pull to interact with your n8n instances. The compare command is particularly useful for preventing accidental overwrites, acting as a diff before you deploy.
This approach is powerful because it allows you to script your entire deployment process in Python, integrating it seamlessly into existing build scripts or more complex CI/CD pipelines. It represents a more advanced, Infrastructure-as-Code (IaC) methodology for managing your automation platform.
A Note on Local Versioning
It is important to distinguish the cross-environment version control we've discussed today from n8n's internal workflow versioning. Within the n8n editor, you can Save snapshots of your work-in-progress and Publish specific versions to be active. This is analogous to making frequent local commits while working on a feature branch. The Git-based source control we've covered is analogous to pushing that feature branch to the remote repository and merging it into main for deployment. The two systems are complementary: one is for iterative development, the other is for deployment and collaboration.
Conclusion
You now have a complete toolkit for managing n8n workflows as code, from simple manual transfers to fully automated, Git-driven CI/CD pipelines. By integrating n8n with version control, you apply the same rigor and best practices to your automations as you would to any other software project.
Key Takeaways:
- Workflows are JSON: The fundamental portability of n8n workflows comes from their JSON structure.
- Manual vs. Automated: You can move workflows manually (copy-paste), programmatically with a "meta-workflow", or using n8n's integrated source control.
- Integrated Source Control: The built-in Git feature is the most robust method, allowing you to
pushfrom dev andpullto prod, aligning with GitOps principles. - CI/CD Automation: A simple GitHub Action can automate the final
pullto your production instance, completing the CI/CD loop. - Code-Centric Alternatives: Python libraries like
n8n-workflow-builderoffer a powerful, CLI-based approach for developers who prefer an IaC model.
In our next lesson, we will turn our attention from deployment to operations. Now that your workflows are running in a production environment, we'll explore how to monitor the health and performance of your self-hosted n8n instance.