Push Multiple Files to GitHub Repository via REST API - n8n Workflow

Automate multi-file uploads to GitHub using a custom n8n workflow and the REST API. Overcome single-file limits with this advanced n8n templates solution for DevOps.

Workflow Preview

Ready to automate?

Download this n8n workflow template and start using it instantly.

Who is this best for?

DevOps professionals and engineers requiring batch file commits.
Users who need to bypass the single-file upload limitation of the native GitHub n8n node.
Automation specialists looking for robust n8n templates for Git operations.
Advanced n8n users focused on custom API scripting and infrastructure as code.

Overview

The standard GitHub n8n node often restricts users to single-file uploads, making large-scale data updates cumbersome. This specialized n8n workflow provides a robust solution by implementing the official Git commit lifecycle via the GitHub REST API. This powerful n8n template allows you to define multiple files and their content within the flow, executing a single, atomic commit that updates all files simultaneously. By utilizing custom HTTP requests, this n8n node sequence ensures granular control over your repository updates, making it essential for complex automation scenarios and reliable Continuous Integration/Continuous Deployment (CI/CD) pipelines. This efficient n8n automation saves significant time compared to sequential single-file operations.

How it Works

This comprehensive n8n workflow is initiated by a manual n8n trigger, designed for easy testing and integration into subsequent automation schedules.


  1. Setup and Initialization: The workflow first uses the 'Set Github Info' node to define essential credentials (Token, Repo, User, Branch, Commit Message). Following this, 'File 1' and 'File 2' Set nodes define the file content that will be pushed to the repository.

  2. Retrieve Current State: The 'Get latest commit SHA' n8n node calls the GitHub API reference endpoint (/git/refs/heads/...) to find the SHA of the most recent commit on the target branch.

  3. Retrieve Base Tree: The 'Get base tree SHA' n8n node then uses the commit SHA to find the SHA of the repository's current file tree.

  4. Create New Tree (Batch Upload): The critical 'Create new tree' n8n node sends a POST request, referencing the base tree SHA. Importantly, this node includes definitions for both file1.txt and file2.txt, along with their content, effectively staging multiple files for commitment in a single payload.

  5. Create Commit Object: The 'Create commit' n8n node receives the new tree SHA and creates a permanent commit object, linking it back to the parent commit and adding the defined commit message.

  6. Final Update: The 'Update branch' n8n node performs a PATCH operation on the branch reference, pointing the branch HEAD to the newly created commit SHA, thus completing the multi-file push operation to your GitHub repository.

Installation Guide

To deploy and utilize this advanced n8n workflow, follow these steps:


  1. Import the n8n Workflow: Copy the provided JSON and import it directly into your n8n instance using the 'Import from JSON' option in the Workflows section.

  2. Generate GitHub Token: Create a GitHub Personal Access Token (PAT). Ensure the token has 'Read and write' permissions under the 'Contents' category for your target repository.

  3. Configure Credentials: Open the 'Set Github Info' n8n node. Replace the placeholder values with your generated PAT (Github Token), Repository Name, Username, Branch name, and desired Commit Message.

  4. Define Files: Modify the 'File 1' and 'File 2' n8n Set nodes to contain the exact content you wish to upload.

  5. Update 'Create New Tree': If you need more or fewer than two files, open the 'Create new tree' n8n node and adjust the 'Body Parameters' to include or remove tree[X].path, tree[X].mode, tree[X].type, and tree[X].content entries as needed. Ensure the content references the appropriate data source (e.g., from an upstream n8n node).

  6. Test: Click the 'Test workflow' n8n trigger to verify the successful commit.

Node Details

When clicking ‘Test workflow’ (manualTrigger): This serves as the initial n8n trigger for immediate execution, allowing developers to test the n8n workflow logic instantaneously.
Set Github Info (Set n8n node): Centralizes all configuration variables (Token, Repo, Branch, etc.) for easy modification and ensures these values are accessible to subsequent n8n nodes via expressions.
File 1 & File 2 (Set n8n nodes): Used to mock or define the file contents that will be pushed to GitHub. In a real-world scenario, these would typically be replaced by file reading nodes (e.g., Google Drive, S3, or local file system).
Get latest commit SHA (httpRequest n8n node): Performs a GET request to retrieve the SHA of the current branch head, utilizing dynamic expressions based on the 'Set Github Info' node.
Create new tree (httpRequest n8n node): The core of the multi-file upload. This n8n node sends a POST request with a complex JSON body containing multiple file definitions, leveraging content input from 'File 1' and 'File 2' Set nodes.
Update branch (httpRequest n8n node): The final step, using a PATCH request to officially update the branch pointer to the new commit, finalizing the execution of this complex n8n workflow.

Related n8n Workflows

Free

Nodes: 4 Nodes
Updated: December 26 2025
View all
Created by

We specializes in crafting tailored automation solutions that help businesses streamline their operations and boost productivity. With expertise in creating custom n8n workflows, we transform complex business processes into seamless, automated systems that save time and reduce manual effort.

Featured*