← 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
- The workflow begins with a manual trigger that initiates the file upload process.
- The "Set Github Info" node configures your GitHub credentials and repository details.
- "File 1" and "File 2" nodes define the content for each file you want to upload.
- The workflow retrieves the latest commit SHA from your specified branch.
- It then obtains the base tree SHA from that commit to build upon.
- A new tree is created that includes all the files you want to upload or update.
- The workflow creates a new commit with your specified commit message.
- 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
- Import the workflow JSON into your n8n instance.
- Create a new GitHub Personal Access Token by visiting GitHub Settings > Developer Settings > Personal Access Tokens.
- When creating the token, select your repository and grant "Read and write" permissions under the "Contents" category.
- Configure the "Set Github Info" node with your:
- GitHub Personal Access Token
- GitHub username
- Repository name
- Branch name (default is "main")
- Commit message
- Modify the "File 1" and "File 2" nodes with the content you want to upload.
- In the "Create new tree" node, update the file paths as needed (default is "public/file1.txt" and "public/file2.txt").
- To add more files, duplicate the tree entries in the "Create new tree" node, incrementing the index for each new file.
- Save and run the workflow to upload your files to GitHub.