
Module 9 Lesson 3: Version Control (Git)
Workflows as code. Learn how to automatically backup your n8n work directly to a GitHub or GitLab repository, enabling version history and easy collaboration.
Module 9 Lesson 3: Version Control (Git)
n8n is "Low-code," but its output is a JSON file. This means we can treat our automations just like "Software code" and store them in Git.
1. Why Git?
- History: "I broke the workflow today! How did it look yesterday?"
- Review: You can "Diff" (compare) two versions of a workflow to see exactly which node changed.
- Rollback: If a new version fails, you can "Re-import" the older version in 5 seconds.
2. Setting up the GitHub Node
n8n has a native GitHub node.
- Trigger: Cron (Every night at 1:00 AM).
- Action: "Get All Workflows" (using the n8n API node).
- Action: "GitHub: Create/Update File" for each workflow.
- Result: Your GitHub repo now stays perfectly in sync with your live n8n instance.
Visualizing the Process
graph TD
Start[Input] --> Process[Processing]
Process --> Decision{Check}
Decision -->|Success| End[Complete]
Decision -->|Retry| Process
3. The "Manual" Export Method
If you don't want to build a workflow, you can use the n8n UI.
- Download: Top right menu -> "Download JSON."
- You can then manually commit this file to your local Git repo.
4. Environment-Specific Git
Professional teams use Brauches:
main: Matches the Production n8n server.develop: Matches the Staging n8n server. When a workflow is finished, you "Promote" it from develop to main.
Exercise: The Git Sync
- Create a private GitHub repository named
my-n8n-backups. - Export your most important workflow as a JSON file.
- Commit that file to your repo.
- Try to "Import" that JSON into a NEW, blank workflow in n8n. Did all your settings and nodes survive?
- Why is it important to EXCLUDE your
Credentialsfrom these Git backups? (Hint: See Module 6, Lesson 2). - Research: What is the "Git" node (community) vs the "GitHub" node?
Summary
Git integration brings "Order" to the chaos of visual programming. By versioning your workflows, you protect yourself from accidental deletions and create a professional environment for your team to build together.
Next Lesson: Checking the pulse: Workflow Health Monitoring (Health-checks).