Automated Backups to GitHub with PR & Notifications - n8n Workflow

Use this robust n8n workflow to automatically backup all new or updated n8n templates to a GitHub repository, create a Pull Request, and notify your team via Slack.

Workflow Preview

Ready to automate?

Download this n8n workflow template and start using it instantly.

Who is this best for?

n8n Administrators and DevOps Engineers who require version control for their n8n templates.
Teams needing reliable, automated backups for critical automation logic.
Users seeking a highly structured, merge-request-based approach to workflow changes.
Anyone wanting to ensure every change to an n8n workflow is tracked and reviewed.

Overview

Maintaining version control for your production n8n workflow environment is essential for stability and compliance. This comprehensive n8n workflow solves the problem of manual backups by integrating directly with your n8n instance's API and GitHub. The automation periodically checks for new n8n templates or updates to existing ones, compares the local state against the remote GitHub repository, and, if differences are detected, initiates a structured Git process. It leverages the power of the n8n node to fetch local data, ensures changes are committed to a feature branch, and automatically creates a Pull Request. Finally, a confirmation is sent via Slack, providing immediate visibility to your operations team. This system guarantees that all changes to any n8n workflow are recorded and subject to review before merging into main.

How it Works

This automation is typically started using an n8n trigger set on a schedule, though it uses a manual trigger in the provided template for easy testing.


  1. Initialization: The 'Define Local Variables' n8n node sets critical runtime variables, including the GitHub owner, repository name, and a unique branch_name timestamped for the run.

  2. Data Retrieval: The workflow simultaneously uses the internal n8n node to list all local n8n workflows and the GitHub n8n node to retrieve all existing backed-up workflows from the repository.

  3. Comparison and Detection: The retrieved GitHub content is Base64 decoded. Two Merge n8n nodes ('Find new workflows' and 'Find updated workflows') then compare the local n8n templates against the remote files. This logic identifies workflows based on ID (new files) and ID + updatedAt timestamp (changed files).

  4. Change Validation: The 'If there are any changes in workflows' n8n node checks if either of the Merge outputs contain data. If no changes exist, the workflow stops via the 'No Operation' node.

  5. Branching and Commit: If changes are found, the workflow fetches the latest commit SHA of the main branch via an HTTP Request n8n node, and then uses a second HTTP Request n8n node to create a new, temporary branch. This ensures changes are isolated.

  6. File Operations: The separate streams for new and updated workflows proceed to use the GitHub n8n node to create or edit the corresponding workflow JSON files within the newly created branch.

  7. Pull Request (PR) Creation: Once all files are committed, an HTTP Request n8n node calls the GitHub API to create a Pull Request, merging the new feature branch back into main.

  8. Notification: Finally, the Slack n8n node sends a notification to a specified channel, including a link to the newly created GitHub PR, confirming the successful backup of the n8n workflow changes.

Installation Guide

To deploy this powerful n8n workflow, follow these steps:


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

  2. n8n API Key Setup: Ensure you have configured an API key for your local n8n instance and set up the corresponding credential in the 'n8n' n8n node. This allows the workflow to read its own configuration.

  3. GitHub Credentials: Set up your GitHub API credentials (Personal Access Token) with repo scope permissions. This credential must be linked to all GitHub and HTTP Request n8n nodes accessing the repository.

  4. Slack Integration: Configure a Slack Bot Token credential for the 'Slack' n8n node if you want notifications.

  5. Configure Variables: Edit the 'Define Local Variables' n8n node and update the githubowner and reponame assignments to match your specific repository configuration. Ensure the repository path exists on GitHub (e.g., workflows/).

  6. Activate: Save and activate the n8n workflow. For continuous backups, set the 'Click me to trigger' n8n trigger to run on a regular schedule (e.g., every 30 minutes).

Node Details

Click me to trigger (Manual Trigger): The starting n8n trigger point for the execution. Meant to be replaced by a Schedule n8n trigger for production.
Define Local Variables (Set): Initializes variables like branchname (timestamped), githubowner (e.g., duynb92), and repo_name (e.g., n8n-workflows). This simplifies configuration.
n8n (n8n node): Fetches a list of all current workflows present on the local n8n instance using the internal API.
Get all workflows on GitHub (GitHub): Fetches the current list of files (workflow backups) stored in the specified GitHub directory (workflows/).
Find new workflows & Find updated workflows (Merge): These Merge n8n nodes compare the local n8n templates against the remote files. They are critical for determining which workflows are new (based on ID) or modified (based on ID and updatedAt).
If there are any changes in workflows (If): A flow control n8n node that decides whether to proceed with the complex Git operation based on whether new or updated n8n workflow items were found.
Get latest commit SHA on main via GitHub API (HTTP Request): Retrieves the SHA needed to correctly create a new Git branch.
Create new commit to add/update workflow (GitHub): Executes the actual file creation and modification operations on the new Git branch, committing the latest n8n workflow JSON data.
Create new PR via GitHub API (HTTP Request): Final action creating the Pull Request for easy review of the automated backup changes.
Slack (Slack n8n node): Sends a successful completion notification, including a hyperlink to the newly generated PR.

Related n8n Workflows

Free

Nodes: 11 Nodes
Updated: December 26 2025
View all
Created by
Bao Duy Nguyen
Bao Duy Nguyen

Featured*