Automatic Workflow Backup to GitHub with Difference Checking - n8n Workflow

Use this powerful n8n workflow to automatically backup all your n8n workflows to GitHub, ensuring version control and history. Features dynamic pathing and efficient difference checking.

Workflow Preview

Ready to automate?

Download this n8n workflow template and start using it instantly.

Who is this best for?

n8n administrators and DevOps teams requiring reliable version control for all production n8n workflow configurations.
Users looking for advanced n8n templates that utilize self-calling recursive workflows.


  • Developers needing a centralized, automated backup solution for their n8n instance.

Overview

This is a critical maintenance n8n workflow solution designed for organizations running n8n in production. It addresses the challenge of workflow loss and configuration drift by providing robust, version-controlled backups of every n8n workflow file (ID.json) to GitHub. The system uses a sophisticated recursive n8n node approach to iteratively fetch and compare the current state of the running workflow against its stored version in the repository.

A key benefit of this n8n workflow is its efficiency. By employing a custom comparison logic within a dedicated Code n8n node, it only interacts with the GitHub API to perform an update if an actual functional difference is detected. This minimizes unnecessary API calls and ensures that your repository history is clean and meaningful. Using this n8n workflow as a foundation, you can guarantee your automation logic is consistently backed up and tracked.

How it Works

The process is initiated either manually using the On clicking 'execute' n8n trigger or automatically via the Schedule Trigger n8n node (configured for a daily run, usually at 7 AM).


  1. Workflow Discovery: The n8n n8n node retrieves a comprehensive list of all published workflows on the current instance.

  2. Recursive Iteration: The Loop Over Items n8n node and the subsequent Execute Workflow n8n node establish a self-calling, recursive loop. This pattern is implemented to handle hundreds of workflows efficiently by processing each item as a sub-workflow call.

  3. Context and Globals: Inside the sub-workflow, the Globals n8n node defines the target GitHub parameters (owner, repo, and dynamic pathing based on workflow tags, handled by the preceding tag? and / n8n nodes).

  4. Check Existing Backup: The Get file data GitHub n8n node attempts to fetch the existing JSON file from the repository. Crucially, it continues on failure if the file is new. If the file is too large for a direct retrieval, If file too large routes the item to Get File (HTTP Request) to download the content via the provided URL.

  5. Difference Analysis: The Merge Items node combines the workflow data and the GitHub file data. The isDiffOrNew Code n8n node then decodes the existing file content (if present), orders the keys in both the old and new JSON objects, and performs a comparison. It assigns a status: "same", "different", or "new".

  6. Action Execution: The Check Status Switch n8n node directs the flow based on the determined status. If the status is "new", the Create new file GitHub n8n node executes. If the status is "different", the Edit existing file GitHub n8n node updates the content. If the status is "same", the n8n workflow completes the item without action.

Installation Guide

To deploy this powerful n8n workflow, follow these steps:


  1. Import: Import this n8n workflow JSON into your n8n instance.

  2. Credentials: Set up or select your GitHub API credentials in the Get file data, Create new file, and Edit existing file n8n nodes. Ensure the credential token has repository read/write access.

  3. API Credentials: Set up your n8n API credentials in the main n8n node so it can list workflows on the instance.

  4. Configuration: Open the Globals n8n node and update the parameters under the Assignments tab:

repo.owner: Your GitHub username/organization name.
repo.name: The name of the repository you wish to use for backups.
* repo.path: The desired subdirectory path (e.g., workflows/). If you wish to use the dynamic tagging feature, keep the existing expression.

  1. Execution: You can run the workflow manually via the Manual Trigger n8n node or rely on the configured Schedule Trigger n8n trigger for daily automation.

Node Details

This n8n workflow utilizes several key nodes to achieve its goal:

Schedule Trigger / Manual Trigger (n8n trigger): Initiates the backup process, providing flexibility for scheduled or ad-hoc runs.
n8n (n8n node): Fetches the list of all workflows from the n8n instance, providing the input data for the main loop.
Execute Workflow (n8n node): Essential for the recursive sub-workflow pattern, enabling efficient iteration over all workflows without overloading memory.
Globals (Set n8n node): Holds critical configuration variables (GitHub repository details) that must be edited before the n8n workflow is activated.
Get file data (GitHub n8n node): Attempts to retrieve the existing workflow backup file from GitHub, crucial for the comparison step. Configured to continue on fail.
If file too large (If n8n node) & Get File (HTTP Request n8n node): Handles cases where GitHub returns a download URL instead of content, ensuring large workflow files are successfully retrieved.
isDiffOrNew (Code n8n node): Contains the core custom scripting logic. This n8n node decodes base64 content, orders JSON keys, and compares the stringified objects to determine if a meaningful change has occurred, setting the githubstatus property.
Check Status (Switch n8n node): Directs the flow based on the github
status calculated by the Code n8n node (new, different, or same).


  • Create new file / Edit existing file (GitHub n8n node): Performs the necessary API operations to commit the current n8n workflow JSON data to the repository, utilizing the appropriate operation based on the status.

Related n8n Workflows

Free

Nodes: 15 Nodes
Updated: December 26 2025
View all
Created by

Featured*