Introduction#
Automatically committing file changes to Git is useful for many scenarios: backing up configuration files, versioning generated documentation, or tracking changes to data files. This tutorial shows you how to build an n8n workflow that watches a folder and automatically commits changes.
Prerequisites#
- An n8n instance (self-hosted recommended for file system access)
- Git installed on the server
- SSH keys or credentials configured for Git push
- A cloned repository on the server
Workflow Overview#
| |
The workflow monitors a directory and triggers whenever files change, then stages, commits, and pushes the changes automatically.
Step-by-Step Setup#
Step 1: Configure the File Trigger#
- Add a Local File Trigger node
- Set the watch path to your target directory (e.g.,
/data/configs/) - Enable recursive watching if you need subdirectories
- Select the events to watch:
change,add,unlink
| |
Step 2: Stage Changes with Git Add#
Add an Execute Command node:
| |
This stages all changes including new files, modifications, and deletions.
Step 3: Create the Commit#
Add another Execute Command node:
| |
The commit message includes a timestamp for easy tracking.
Step 4: Push to Remote#
Add a final Execute Command node:
| |
Enhanced Workflow Options#
Add File Details to Commit Message#
Include which file changed in the commit message:
| |
Debounce Rapid Changes#
If files change frequently, add a Wait node to batch changes:
| |
Add Error Handling#
Wrap commands in error handling to catch failures:
| |
Notify on Success#
Add a Slack notification after successful push:
| |
Testing the Workflow#
- Activate the workflow in n8n
- Create or modify a file in the watched directory
- Check the n8n execution log
- Verify the commit appears in your Git history:
| |
Troubleshooting#
Permission Denied on Push#
- Ensure SSH keys are configured for the n8n user
- Or use HTTPS with credentials stored in Git credential helper
Nothing to Commit#
- The file might not be in the repository’s tracked path
- Check
.gitignoreisn’t excluding the files
Workflow Triggers Too Often#
- Add debouncing with a Wait node
- Or filter specific file patterns in the trigger
Security Considerations#
- Limit watched directories - Don’t watch sensitive paths
- Use deploy keys - Create repo-specific SSH keys with limited permissions
- Review before production - Test thoroughly in a non-production repo first
Conclusion#
Auto-committing file changes with n8n provides a simple backup and versioning solution for configurations, documentation, or any files that change regularly. Download the complete workflow from our n8n Workflow Gallery and adapt it to your needs.
