Automating Git Commits with n8n
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
File Change Detected → Git Add → Git Commit → Git PushThe 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
{
"path": "/data/configs/",
"events": ["change", "add", "unlink"],
"recursive": true
}Step 2: Stage Changes with Git Add
Add an Execute Command node:
cd /path/to/repo && git add -AThis stages all changes including new files, modifications, and deletions.
Step 3: Create the Commit
Add another Execute Command node:
cd /path/to/repo && git commit -m "Auto-commit: $(date '+%Y-%m-%d %H:%M:%S')"The commit message includes a timestamp for easy tracking.
Step 4: Push to Remote
Add a final Execute Command node:
cd /path/to/repo && git push origin mainEnhanced Workflow Options
Add File Details to Commit Message
Include which file changed in the commit message:
cd /path/to/repo && git commit -m "Auto-commit: {{ $json.path }} changed at $(date '+%Y-%m-%d %H:%M:%S')"Debounce Rapid Changes
If files change frequently, add a Wait node to batch changes:
File Trigger → Wait (30 seconds) → Git Add → Git Commit → Git PushAdd Error Handling
Wrap commands in error handling to catch failures:
cd /path/to/repo && git add -A && git commit -m "Auto-commit" || echo "Nothing to commit"Notify on Success
Add a Slack notification after successful push:
Git Push → Slack: "Changes pushed to repo"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:
git log --oneline -5Troubleshooting
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.