Contents

Automating Git Commits with n8n

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.

Download the Workflow
Get the ready-to-use workflow from our n8n Workflow Gallery.
  • 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
File Change Detected → Git Add → Git Commit → Git Push

The workflow monitors a directory and triggers whenever files change, then stages, commits, and pushes the changes automatically.

  1. Add a Local File Trigger node
  2. Set the watch path to your target directory (e.g., /data/configs/)
  3. Enable recursive watching if you need subdirectories
  4. Select the events to watch: change, add, unlink
{
  "path": "/data/configs/",
  "events": ["change", "add", "unlink"],
  "recursive": true
}

Add an Execute Command node:

cd /path/to/repo && git add -A

This stages all changes including new files, modifications, and deletions.

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.

Add a final Execute Command node:

cd /path/to/repo && git push origin main

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')"

If files change frequently, add a Wait node to batch changes:

File Trigger → Wait (30 seconds) → Git Add → Git Commit → Git Push

Wrap commands in error handling to catch failures:

cd /path/to/repo && git add -A && git commit -m "Auto-commit" || echo "Nothing to commit"

Add a Slack notification after successful push:

Git Push → Slack: "Changes pushed to repo"
  1. Activate the workflow in n8n
  2. Create or modify a file in the watched directory
  3. Check the n8n execution log
  4. Verify the commit appears in your Git history:
git log --oneline -5
  • Ensure SSH keys are configured for the n8n user
  • Or use HTTPS with credentials stored in Git credential helper
  • The file might not be in the repository’s tracked path
  • Check .gitignore isn’t excluding the files
  • Add debouncing with a Wait node
  • Or filter specific file patterns in the trigger
  1. Limit watched directories - Don’t watch sensitive paths
  2. Use deploy keys - Create repo-specific SSH keys with limited permissions
  3. Review before production - Test thoroughly in a non-production repo first

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.