Backup and Sync n8n Workflows with GitHub Automation

This n8n workflow automates backing up and syncing your n8n workflows to GitHub, ensuring you always have versioned copies and real-time updates. It compares workflows for changes, creates new backups, and edits existing GitHub files to keep your automation safe and organized.
github
httpRequest
function
+7
Workflow Identifier: 1617
NODES in Use: Manual Trigger, HTTP Request, Function, GitHub, Merge, Switch, NoOp, SplitInBatches, Set, Cron
Automate n8n workflow backup with GitHub

Press CTRL+F5 if the workflow didn't load.

Learn how to Build this Workflow with AI:

What this workflow does

This workflow automatically backs up n8n workflows to a GitHub repository. It checks each local workflow and compares it with the saved version on GitHub. It creates new files or updates existing ones if changes are detected. If no change happens, it skips the update. This saves time and avoids manual errors in backup.

The main problem solved is avoiding manual exporting and syncing of workflows that takes hours and can cause mistakes or missed updates. The outcome is safe, version-controlled backups stored on GitHub without extra effort.


Who should use this workflow

This is for people who manage many n8n workflows and want to keep their backups saved automatically on GitHub. It fits those who want to save time and improve reliability in version control. Users of self-host self-host n8n or local n8n setups will find it useful.


Tools and services used

  • n8n Local REST API: To fetch current workflows.
  • GitHub API: To get, create, or update workflow JSON files.
  • n8n Nodes: HTTP Request, Function, GitHub, Merge, Switch, SplitInBatches, Manual Trigger.

Inputs, Processing Steps, and Output

Inputs

Processing Steps

  • Split the workflows array to process items one by one.
  • Fetch each workflow’s file from GitHub if it exists.
  • Get detailed full JSON for each workflow from local n8n.
  • Compare GitHub and local workflow JSON for changes.
  • Use a switch to route each workflow as “same”, “different”, or “new”.
  • Skip actions for unchanged workflows.
  • Edit files on GitHub if workflows are changed.
  • Create new files on GitHub if workflows are new.

Output

Updated or new workflow JSON files in the GitHub repository matched with local workflows. Unchanged workflow backups remain untouched.


Beginner step-by-step: How to use this in n8n

Step 1: Import the workflow

Use the Download button to get the workflow file.

Go to the n8n editor and choose Import from File to load the workflow.

Step 2: Add credentials

Insert your GitHub API credentials with proper access to the backup repository.

Ensure the HTTP Request nodes can reach your local or cloud n8n REST API URL. Change URL if not on localhost.

Step 3: Configure repository info

In the Globals Set node, update repo.owner, repo.name, and repo.path to your GitHub account and folder.

Step 4: Test the workflow

Run the workflow manually with the Manual Trigger node to verify it fetches workflows and compares them correctly.

Step 5: Activate for ongoing use

Turn on the workflow by toggling the switch for automated runs.

Optionally, replace Manual Trigger with a Cron node to schedule daily backups.


Explanation of key code snippet for comparison

The isDiffOrNew function node compares JSON from GitHub and local n8n workflows.

It decodes the GitHub file content from Base64 and orders keys alphabetically in both JSON objects. Then it compares the JSON strings.

If they are exactly the same, it sets status to “same”. If different, it sets “different”. If no file found on GitHub, it sets “new”.

// File Returned with Content
if (Object.keys(items[0].json).includes("content")) {
  var origWorkflow = eval("(\"+Buffer.from(items[0].json.content, 'base64').toString()+")");
  var n8nWorkflow = (items[1].json.data);
  
  var orderedOriginal = {}
  var orderedActual = {}
  
  Object.keys(origWorkflow).sort().forEach(function(key) {
    orderedOriginal[key] = origWorkflow[key];
  });
  
  Object.keys(n8nWorkflow).sort().forEach(function(key) {
    orderedActual[key] = n8nWorkflow[key];
  });
  
  if ( JSON.stringify(orderedOriginal) === JSON.stringify(orderedActual) ) {
    items[0].json.github_status = "same";
    items[0].json.content_decoded = orderedOriginal;
  } else {
    items[0].json.github_status = "different";
    items[0].json.content_decoded = orderedOriginal;
    items[0].json.n8n_data_stringy = JSON.stringify(orderedActual, null, 2);
  }
} else {
  var n8nWorkflow = (items[1].json.data);
  var orderedActual = {}
  Object.keys(n8nWorkflow).sort().forEach(function(key) {
    orderedActual[key] = n8nWorkflow[key];
  });
  
  items[0].json.github_status = "new";
  items[0].json.n8n_data_stringy = JSON.stringify(orderedActual, null, 2);
}
return items;

Edge cases and error fixes

  • 404 GitHub File Not Found: Happens when file is not on GitHub yet. Use the “new” path with create node to fix.
  • GitHub API Rate Limits: Too many requests cause errors. Keep batch size to 1 and add delays or upgrade GitHub plan.
  • False “different” comparison: Happens if JSON keys reorder. The workflow orders keys before comparing, so keep that logic unchanged.

Customization options

  • Change backup folder by editing repo.path in Globals node.
  • Increase batch size in SplitInBatches to process more workflows at once, but watch API limits.
  • Edit commit messages in GitHub nodes for better version notes.
  • Add email notifications after updates with Gmail or SMTP nodes.
  • Clone workflow and change repo data to back up to more repositories.

Summary of benefits and results

✓ Save time by automating workflow backups.
✓ Avoid manual errors and missed updates.
✓ Keep version history of workflows in GitHub.
✓ Process workflows one by one to avoid conflicts.
✓ Flexible scheduling with manual or Cron triggers.


Automate n8n workflow backup with GitHub

Visit through Desktop to Interact with the Workflow.

Frequently Asked Questions

Yes. Adjust all HTTP Request URLs to point to the cloud-hosted n8n REST API endpoint.
No. It processes one workflow at a time and skips unchanged files, reducing calls.
Yes. Using private repos and correct API Key scopes keeps data secure on GitHub.
Yes. Duplicate the workflow and update Globals node with new repository details.

Promoted by BULDRR AI

Related Workflows

Automate Twist Channel Creation and Messaging with n8n

This workflow automates creating and updating a channel in Twist and sending a personalized message to specific users. It eliminates manual setup errors and saves time managing Twist communications.

Automate Ideogram Image Generation with Google Sheets & Gmail

This workflow automates graphic design image generation via Ideogram AI, storing image data in Google Sheets and Google Drive, with email alerts via Gmail. It saves designers hours by automating image creation, remixing, review, and record-keeping.

Automate IT Support with Slack and OpenAI in n8n

Streamline IT support by automating Slack message handling using n8n and OpenAI. This workflow handles Slack DMs, filters bots, queries a Confluence knowledge base, and delivers AI-generated responses, improving support efficiency and response time.

Automate Crypto Analysis with CoinMarketCap & n8n AI Agent

Discover how this unique n8n workflow leverages CoinMarketCap’s multi-agent AI to deliver precise, real-time cryptocurrency insights directly via Telegram. Manage crypto data analysis efficiently with automated multi-source API integration.

Automate Gumroad to Beehiiv Subscriber Sync with n8n

Learn how to automatically add new Gumroad sales customers as Beehiiv newsletter subscribers using n8n automation. This workflow saves time by syncing sales data to Google Sheets CRM and notifying your Telegram channel instantly.

Generate On-Brand Blog Articles Using n8n and OpenAI

This workflow automates the creation of on-brand blog articles by analyzing existing company content using n8n and OpenAI. It extracts article structures and brand voice to produce consistent draft articles, saving significant content creation time.
1:1 Free Strategy Session
Your competitors are already automating. Are you still paying for it manually?

Do you want to adopt AI Automation?

Every hour your team does repetitive work, you're burning real money.
While you wait, faster businesses are cutting costs and moving quicker.
AI and automations aren't the future anymore — they're the present.

Book a live 1-on-1 session where we show you exactly which of your daily tasks can be automated — and what it’s costing you not to.