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

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

Learn how to Build this Workflow with AI:

Visit through Desktop for Best experience

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

  • Local n8n workflows fetched via REST API.
  • Existing workflow JSON backup files from GitHub repository.

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.


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 Viral UGC Video Creation Using n8n + Degaus (Beginner-Friendly Guide)

Learn how to automate viral UGC video creation using n8n, AI prompts, and Degaus. This beginner-friendly guide shows how to import, configure, and run the workflow without technical complexity.
Form Trigger
Google Sheets
Gmail
+37
Free

AI SEO Blog Writer Automation Workflows in n8n

A complete beginner guide to building an AI SEO blog writer automation using n8n.
AI Agent
Google Sheets
httpRequest
+5
Free

Automate CrowdStrike Alerts with VirusTotal, Jira & Slack

This workflow automates processing of CrowdStrike detections by enriching threat data via VirusTotal, creating Jira tickets for incident tracking, and notifying teams on Slack for quick response. Save hours daily by transforming complex threat data into actionable alerts effortlessly.
scheduleTrigger
httpRequest
jira
+5
Free

Automate Telegram Invoices to Notion with AI Summaries & Reports

Save hours on financial tracking by automating invoice extraction from Telegram photos to Notion using Google Gemini AI. This workflow extracts data, records transactions, and generates detailed spending reports with charts sent on schedule via Telegram.
lmChatGoogleGemini
telegramTrigger
notion
+9
Free

Automate Email Replies with n8n and AI-Powered Summarization

Save hours managing your inbox with this n8n workflow that uses IMAP email triggers, AI summarization, and vector search to draft concise replies requiring minimal review. Automate business email processing efficiently with AI guidance and Gmail integration.
emailReadImap
vectorStoreQdrant
emailSend
+12
Free

Automate Email Campaigns Using n8n with Gmail & Google Sheets

This n8n workflow automates personalized email outreach campaigns by integrating Gmail and Google Sheets, saving hours of manual follow-up work and reducing errors in email sequences. It ensures timely follow-ups based on previous email interactions, optimizing communication efficiency.
googleSheets
gmail
code
+5
Free