⚙️ Sync workflows to GitHub repository files using the n8n API
⚡ 9 views · ⚙️ DevOps & CI/CD
💡 Pro Tip — If you need GitHub data beyond what the REST API gives you, ScraperNode has a repository scraper that extracts metadata at scale without token rate limits.
Description
Quick overview
This workflow is called by another n8n workflow to export a selected n8n workflow as a JSON file and sync it to a GitHub repository, creating the file if it doesn’t exist and updating it only when the workflow definition changes.
How it works
- Receives a workflow ID as input when executed by another n8n workflow.
- Fetches the workflow definition from the n8n API using the provided workflow ID.
- Reduces the workflow data to essential fields (such as name, nodes, connections, and settings) and converts it into a formatted JSON file.
- Tries to retrieve a same-named JSON file from a GitHub repository.
- If the file does not exist, creates it in GitHub with an initial commit message.
- If the file exists and the content differs from the current workflow JSON, updates the GitHub file with a new commit.
Setup
- Create an n8n API credential with access to read workflows and select it in the n8n node used to fetch workflows.
- Add a GitHub credential with permission to read and write files in the target repository.
- Update the GitHub owner and repository values (and optionally the commit message patterns) to match where you want to store the exported workflow JSON files.
- Ensure the calling workflow passes a valid “Workflow Id” input when executing this workflow.
🔗 Nodes Used
GitHub, n8n, Execute Workflow Trigger, Convert to File
📥 Import
Download workflow.json and import into n8n:
Workflow menu → Import from File