Push Multiple Files to Github Repo via Github REST API

For GitHub, this workflow automates the process of uploading multiple files to a repository using the GitHub REST API. It overcomes the limitation of single-file uploads by enabling batch operations, streamlining file management. Users can easily configure their GitHub credentials and file content, resulting in efficient updates to their repositories with minimal manual effort.

7/8/2025
10 nodes
Medium
manualmediumsticky noteapiintegration
Categories:
Manual TriggeredMedium Workflow
Integrations:
Sticky Note

Target Audience

This workflow is ideal for:
- Developers looking to automate file uploads to GitHub repositories without manual intervention.
- DevOps Engineers who need to maintain codebases by pushing multiple files efficiently.
- Project Managers overseeing projects that require frequent updates to documentation or code files in GitHub.
- Teams collaborating on projects that involve multiple file changes and need a streamlined process for version control.

Problem Solved

This workflow addresses the limitation of the native GitHub n8n node, which only supports single-file uploads. By leveraging the GitHub REST API, this solution enables users to:
- Batch upload multiple files simultaneously to their GitHub repositories, enhancing productivity.
- Automate the process of committing and pushing changes, reducing the risk of human error and saving time.
- Ensure that updates are made consistently and efficiently, especially in collaborative environments.

Workflow Steps

  • Trigger the Workflow: The process begins with a manual trigger, allowing users to start the workflow as needed.
    2. Set GitHub Information: Users input their GitHub credentials, including the GitHub Personal Access Token, repository name, username, branch, and a commit message.
    3. Prepare File Contents: The workflow defines the contents of the files to be uploaded (e.g., file1.txt and file2.txt).
    4. Get Latest Commit SHA: The workflow retrieves the SHA of the latest commit on the specified branch to ensure the new commit is based on the latest changes.
    5. Get Base Tree SHA: It fetches the base tree SHA from the latest commit, which is necessary for creating a new tree with the updated files.
    6. Create New Tree: A new tree is created that includes the new file contents, which are specified in the workflow parameters.
    7. Create Commit: A new commit is formed with a message and references the newly created tree and the parent commit.
    8. Update Branch: Finally, the branch is updated with the new commit, effectively pushing the changes to the GitHub repository.
  • Customization Guide

    Users can easily customize this workflow by:
    - Modifying File Contents: Change the content of File 1 and File 2 to suit their needs by updating the values in the respective nodes.
    - Adding More Files: To include additional files, users can append more entries in the Create new tree node with the desired file paths and contents.
    - Updating GitHub Info: Replace the placeholders in the Set Github Info node with actual values for their GitHub account and repository.
    - Changing Branch or Commit Message: Adjust the branch or commit message in the Set Github Info node to reflect the specific updates being made.