Automated Deployment and Synchronization of Workflows via GitHub GitOps - n8n Workflow

Use this powerful n8n workflow to automatically synchronize and deploy changes to your n8n templates every time a Pull Request is merged on GitHub, enabling a true GitOps approach.

Workflow Preview

Ready to automate?

Download this n8n workflow template and start using it instantly.

Who is this best for?


  • DevOps Engineers managing infrastructure as code.

  • Developers using Git for version control of their n8n templates.

  • Advanced n8n users requiring a reliable, automated backup and synchronization strategy for their n8n workflow configurations.

  • Teams implementing GitOps principles for automation deployments.

Overview

Managing changes to complex automation flows can be challenging without proper version control. This specific n8n workflow solves the problem of manual deployment by implementing a GitOps strategy. Every time a development team merges a Pull Request containing changes to stored n8n workflow JSON files, this n8n automation template ensures those changes are instantly reflected in the running n8n instance. This eliminates human error, provides an audit trail via Git, and guarantees that your live n8n environment always matches the approved code in your repository. This process utilizes the internal n8n API, making the synchronization seamless and highly efficient for updating or creating new n8n workflow items.

How it Works

The entire process is initiated by a single n8n trigger event from GitHub.


  1. Trigger and Initialization: The n8n workflow starts with the Github Trigger - When there is new pull request node, listening for any pull request event on the configured repository.

  2. Flow Control Filter: The next n8n node, Check if trigger event is pull request merged, acts as a gatekeeper. It strictly checks if the incoming payload action is 'closed' AND if the PR was successfully merged. If these conditions are met, the automation proceeds.

  3. Fetch Commit Details: Using the mergecommitsha provided by the trigger payload, the workflow fetches the detailed commit information via a GitHub API request. This detail includes a list of all files that were modified, added, or deleted.

  4. Identify Changed Files: The Get files changes details node uses the Split Out function to create one n8n item for every file changed in the merge commit.

  5. Branching Logic (Modified vs. Added): The flow splits into two paths using filter n8n node branches:

a. The 'Modified' path handles existing n8n workflow files (status = 'modified').
b. The 'Created' path handles new n8n workflow files (status = 'added').

  1. Fetch and Decode Content: Both branches use the GitHub n8n node to fetch the raw content of the workflow JSON file from the repository. This content is typically base64 encoded. The subsequent Set n8n node uses the base64Decode() function to convert the content back into a usable JSON object.

  2. Final Deployment: The n8n node takes the decoded JSON:

a. For modified files, it executes an 'update' operation, using the existing workflow ID found in the JSON data.
b. For added files, it executes a 'create' operation, introducing the new n8n workflow to the instance.

Installation Guide

To deploy this powerful n8n workflow, follow these steps:


  1. Import the n8n Template: Copy the provided JSON and import it directly into your n8n instance as a new workflow.

  2. GitHub Credentials Setup: Configure the GitHub Trigger node and the subsequent GitHub API credentials. It is highly recommended to use a Personal Access Token (PAT) classic with repo and admin:repohook scopes enabled, as detailed in the sticky note within the n8n workflow.

  3. n8n API Credentials Setup: You must provide n8n API credentials for the internal communication. Configure the API Key credentials for the Update workflow in n8n and Create new workflow in n8n n8n node actions. This allows the workflow to manage the workflows on the host instance.

  4. Configure Repository Variables: Update the Define Local Variables n8n node to accurately reflect your GitHub repository details (githubowner and reponame).

  5. Activate GitHub Webhook: Ensure that your target GitHub repository has a webhook configured for pullrequest events, pointing to the webhook URL exposed by the initial Github Trigger n8n node. Then, activate the n8n workflow.

Node Details

Github Trigger - When there is new pull request (n8n trigger): The entry point of the n8n workflow. It uses a webhook to listen for pull request events on a specified repository.
Define Local Variables (Set n8n node): Stores essential configuration details like githubowner and reponame for reuse throughout the n8n automation.
Check if trigger event is pull request merged (Filter n8n node): Crucial flow control step that ensures subsequent actions only occur if the PR action is 'closed' and the PR was actually 'merged'.
Fetch merged commit details via GitHub API (HTTP Request n8n node): Uses the dynamic mergecommitsha from the trigger data to retrieve the full commit details, specifically identifying all modified files.
Get files changes details (Split Out n8n node): Splits the JSON array of changed files into individual items, allowing the n8n workflow to process each file independently.
Filter modified/created workflows (Filter n8n node): Separates items based on file status ('modified' or 'added') to determine whether an 'update' or 'create' operation is needed on the running n8n instance.
Fetch workflow content from Git (GitHub n8n node): Connects back to GitHub to retrieve the base64-encoded file content for the specific n8n workflow file path.
Decode workflow content to json (Set n8n node): Decodes the base64 content into valid JSON structure required for the next n8n node operation.


  • Update workflow in n8n / Create new workflow in n8n (n8n n8n node): These nodes communicate with the n8n API to perform the final automated deployment, either updating an existing n8n workflow using its ID or deploying a brand new n8n workflow.

Related n8n Workflows

Free

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

Featured*