Git Repository Backup for Workflow Configurations - n8n Workflow

Use this robust n8n workflow to automatically synchronize and backup all your n8n workflows to a GitLab repository, ensuring robust version control and easy recovery using custom logic.

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 managing production instances.
Users needing robust version control for their crucial n8n workflow definitions.
Organizations requiring compliance tracing for automation configuration changes.
Anyone looking for advanced n8n templates for configuration management.

Overview

Managing numerous n8n workflows across various environments can lead to configuration drift and loss of critical automation logic. This powerful n8n workflow serves as an essential DevOps tool, automating the continuous backup and version control of every n8n workflow defined on your instance into a dedicated GitLab repository.

The automation automatically retrieves the JSON definitions of all your active workflows and compares them against the stored versions in Git. Crucially, the custom logic ignores benign changes (like updatedAt timestamps) to accurately detect meaningful differences. If a new n8n workflow is found, it is committed; if an existing one has been modified (a 'diff' status), the file is updated. This guarantees that your n8n templates are always synchronized with a reliable external source, mitigating risk and streamlining deployment.

How it Works

This comprehensive n8n workflow operates on a manual trigger, typically scheduled for periodic execution, but starting when clicking the "Test Workflow" button:


  1. Initialization: The n8n trigger starts the process. A 'Globals' n8n node sets the essential GitLab repository parameters (Owner, Repo Name, Branch, Path).

  2. Retrieve Workflows: The specialized internal n8n node (titled 'Retrieve all workflows') fetches the JSON definition for every active n8n workflow on the instance.

  3. Looping: The 'Loop Over Workflows' n8n node processes each retrieved n8n workflow definition sequentially.

  4. GitLab Check: A GitLab n8n node attempts to 'Get file' using the workflow's ID as the filename. The workflow uses error handling to treat a file-not-found error (status: 'new') as a normal output item, ensuring new workflows are processed correctly.

  5. Data Comparison: The 'File status' Code n8n node executes custom JavaScript logic. This code meticulously compares the live n8n workflow JSON against the version retrieved from GitLab, intelligently ignoring transient fields like updatedAt and global to accurately determine if the workflow is 'new', 'same', or 'diff'.

  6. Action Routing: A Switch n8n node routes the flow based on the determined status:

New: Uses a GitLab n8n node to 'Create file' for the new n8n workflow definition.
Diff: Uses a GitLab n8n node with the 'Edit' operation to commit the updated workflow JSON.
* Same/Error: Records the status and terminates the loop iteration. All paths converge at the 'End Loop' n8n node to continue to the next item.

Installation Guide

To deploy this n8n template, follow these steps:


  1. Import: Import the provided n8n workflow JSON into your n8n instance.

  2. Credentials: Set up the required credentials:

GitLab API: Create a GitLab credential, ensuring it has the necessary permissions (read/write access) to the target repository.
n8n API: Create an n8n API credential. This allows the workflow to use the internal n8n node to fetch workflow definitions.

  1. Configuration: Update the 'Globals' n8n node parameters (repo.owner, repo.name, repo.branch, repo.path) to match your specific GitLab repository structure where the n8n templates should be stored.

  2. Testing: Run the workflow using the manual n8n trigger to verify files are correctly synced to GitLab.

Node Details

When clicking "Test Workflow" (Manual Trigger): The starting n8n trigger point for execution.
Globals (Set Node): Central configuration node. Stores variables like repo.owner and repo.path necessary for the GitLab n8n node operations.
Retrieve all workflows (n8n Node): Crucial n8n node that makes an internal API call to list and retrieve the JSON definition of all currently saved n8n workflow configurations.
Get file (GitLab Node): Attempts to retrieve the existing workflow file from GitLab. Uses onError: continueErrorOutput to handle new files where the retrieval fails gracefully.
File status (Code Node): Contains custom scripting to compare the retrieved Git version (workflow-from-gitlab) with the current n8n version (workflow-from-n8n), defining the status as 'new', 'same', or 'diff'. This comparison logic is the core of the n8n workflow.
Switch (Switch Node): Routes execution based on the 'status' variable generated by the Code n8n node.


  • Create file / New file version (GitLab Nodes): Executes the write operations to GitLab. 'Create file' handles 'new' n8n workflows, while 'New file version' handles updated ('diff') n8n templates by using the 'edit' operation.

Related n8n Workflows

Free

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

Featured*