This workflow offers a streamlined solution for uploading multiple files to a GitHub repository simultaneously using GitHub's REST API. It addresses a significant limitation of n8n's native GitHub node, which only supports single-file uploads at a time. By leveraging GitHub's Git Data API, this workflow creates a new Git tree containing multiple files, commits this tree, and updates the target branch—all in a single automated process.
The workflow is particularly valuable for automation scenarios that require batch file operations, such as deploying website updates, publishing documentation, or maintaining configuration files across repositories. It eliminates the need for multiple separate API calls when working with multiple files, making your automation more efficient and less prone to partial update issues.
By abstracting the complexities of GitHub's Git Data API into a reusable workflow, it provides a practical solution for developers, content managers, and DevOps professionals who need to programmatically manage repository content at scale.
This workflow is designed for:
Users should have basic familiarity with GitHub concepts (repositories, branches, commits) and should be comfortable obtaining and using GitHub Personal Access Tokens. While the workflow handles the API complexity, users should understand the fundamentals of version control to effectively utilize and customize it.
This workflow addresses several key challenges:
Limited batch operations: n8n's native GitHub node only supports uploading one file at a time, making multi-file operations cumbersome and inefficient.
API complexity: GitHub's Git Data API requires multiple sequential calls with interdependent data to create commits with multiple files, which is complex to implement manually.
Automation bottlenecks: Without this workflow, automating multi-file updates would require either multiple separate API calls (risking partial updates) or custom scripting outside of n8n.
Consistency issues: When files need to be updated together (e.g., code and corresponding documentation), this workflow ensures they're committed in a single atomic operation.
By solving these issues, the workflow enables reliable, atomic updates of multiple files, maintaining repository consistency and simplifying automation processes.
This workflow uses GitHub's REST API to push multiple files to a repository in a single operation. It follows Git's internal model by:
Initialization: The workflow starts with a manual trigger and sets up GitHub credentials and repository information.
File Content Definition: Two "Set" nodes define the content for the files to be uploaded.
Repository State Retrieval:
Tree Creation: A new Git tree is created that includes both files (file1.txt and file2.txt), specifying their paths and content.
Commit Creation: A new commit is created with the specified commit message, referencing the new tree and the parent commit.
Branch Update: Finally, the branch reference is updated to point to the new commit, making the changes visible in the repository.
To use this workflow:
Import the workflow: Download the workflow JSON and import it into your n8n instance.
Create a GitHub Personal Access Token:
Configure the workflow:
Define file content:
Adjust file paths if needed:
Save and run the workflow: Click "Test workflow" to execute the process.
This workflow can be adapted in several ways:
Add more files:
Change file locations:
Dynamic file content:
Conditional file updates:
Scheduled updates:
Error handling: