← Back to Templates

Push Multiple Files to GitHub Repository via Github REST API | n8n Workflow Template

GitHubFree
2025-03-24

Workflow Diagram

Tip: CTRL + Mouse wheel to zoom, click and drag to pan

Push Multiple Files to GitHub Repository n8n Template

This workflow solves a significant limitation of the native GitHub n8n node by enabling you to upload multiple files to a GitHub repository in a single operation. By leveraging GitHub's REST API directly, you can batch file operations for more efficient repository management and automation scenarios that require simultaneous uploads.

How It Works

  1. The workflow begins with a manual trigger that initiates the file upload process.
  2. The "Set Github Info" node configures your GitHub credentials and repository details.
  3. "File 1" and "File 2" nodes define the content for each file you want to upload.
  4. The workflow retrieves the latest commit SHA from your specified branch.
  5. It then obtains the base tree SHA from that commit to build upon.
  6. A new tree is created that includes all the files you want to upload or update.
  7. The workflow creates a new commit with your specified commit message.
  8. Finally, it updates the branch reference to point to your new commit, completing the file upload process.

Benefits

  • Upload multiple files in a single operation, unlike the native GitHub node's one-file limitation
  • Maintain proper Git commit history with custom commit messages
  • Automate file updates without requiring local Git installations
  • Easily expandable to handle any number of files by adding more entries to the tree
  • Perfect for automation scenarios requiring batch file operations

Requirements

  • GitHub account
  • GitHub Personal Access Token with "Contents" write permissions
  • GitHub repository where you want to upload files
  • n8n instance to run the workflow

Setup Instructions

  1. Import the workflow JSON into your n8n instance.
  2. Create a new GitHub Personal Access Token by visiting GitHub Settings > Developer Settings > Personal Access Tokens.
  3. When creating the token, select your repository and grant "Read and write" permissions under the "Contents" category.
  4. Configure the "Set Github Info" node with your:
    • GitHub Personal Access Token
    • GitHub username
    • Repository name
    • Branch name (default is "main")
    • Commit message
  5. Modify the "File 1" and "File 2" nodes with the content you want to upload.
  6. In the "Create new tree" node, update the file paths as needed (default is "public/file1.txt" and "public/file2.txt").
  7. To add more files, duplicate the tree entries in the "Create new tree" node, incrementing the index for each new file.
  8. Save and run the workflow to upload your files to GitHub.
Download Template

Stay Updated with AI Workflows

Join our newsletter for the latest automation tips, exclusive templates, and worthy n8n updates.

We respect your privacy. No spam, ever.

Need a Custom Workflow?

We can create a tailored workflow solution specifically for your business needs.