{
  "name": "Push Multiple Files to Github Repo via Github REST API",
  "nodes": [
    {
      "parameters": {
        "url": "=https://api.github.com/repos/{{ $('Set Github Info').item.json['Github Username'] }}/{{ $('Set Github Info').item.json['Github Repo'] }}/git/refs/heads/{{ $('Set Github Info').item.json['Github Branch'] }}",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "=Bearer {{ $('Set Github Info').item.json['Github Token'] }}"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        -300,
        180
      ],
      "id": "f9de827d-6aea-47f9-ac01-bf41e9a41642",
      "name": "Get latest commit SHA"
    },
    {
      "parameters": {
        "url": "=https://api.github.com/repos/{{ $('Set Github Info').item.json['Github Username'] }}/{{ $('Set Github Info').item.json['Github Repo'] }}/git/commits/{{ $json.object.sha }}",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "=Bearer {{ $('Set Github Info').item.json['Github Token'] }}"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        -120,
        180
      ],
      "id": "28576f1f-2e41-46fe-9bb3-9e4678bb3f45",
      "name": "Get base tree SHA"
    },
    {
      "parameters": {
        "method": "POST",
        "url": "=https://api.github.com/repos/{{ $('Set Github Info').item.json['Github Username'] }}/{{ $('Set Github Info').item.json['Github Repo'] }}/git/trees",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "=Bearer {{ $('Set Github Info').item.json['Github Token'] }}"
            },
            {
              "name": "Content-Type",
              "value": "application/json"
            }
          ]
        },
        "sendBody": true,
        "bodyParameters": {
          "parameters": [
            {
              "name": "base_tree",
              "value": "={{ $json[\"tree\"][\"sha\"] }}"
            },
            {
              "name": "tree[0].path",
              "value": "public/file1.txt"
            },
            {
              "name": "tree[0].mode",
              "value": "100644"
            },
            {
              "name": "tree[0].type",
              "value": "blob"
            },
            {
              "name": "tree[0].content",
              "value": "={{ $('File 1').item.json.content }}"
            },
            {
              "name": "tree[1].path",
              "value": "public/file2.txt"
            },
            {
              "name": "tree[1].mode",
              "value": "100644"
            },
            {
              "name": "tree[1].type",
              "value": "blob"
            },
            {
              "name": "tree[1].content",
              "value": "={{ $('File 2').item.json.content }}"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        60,
        180
      ],
      "id": "eb3c7f72-a2bd-4ef2-ae9d-e548746a1260",
      "name": "Create new tree"
    },
    {
      "parameters": {
        "method": "POST",
        "url": "=https://api.github.com/repos/{{ $('Set Github Info').item.json['Github Username'] }}/{{ $('Set Github Info').item.json['Github Repo'] }}/git/commits",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "=Bearer {{ $('Set Github Info').item.json['Github Token'] }}"
            },
            {
              "name": "Content-Type",
              "value": "application/json"
            }
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={\n  \"message\": \"{{ $('Set Github Info').item.json['Github Commit Update Message'] }}\",\n  \"tree\": \"{{ $json.sha }}\",\n  \"parents\": [\"{{ $('Get latest commit SHA').item.json.object.sha }}\"]\n}",
        "options": {}
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        240,
        180
      ],
      "id": "ba76ddd3-844a-4aa1-8a5a-efaa2f228044",
      "name": "Create commit"
    },
    {
      "parameters": {
        "method": "PATCH",
        "url": "=https://api.github.com/repos/{{ $('Set Github Info').item.json['Github Username'] }}/{{ $('Set Github Info').item.json['Github Repo'] }}/git/refs/heads/{{ $('Set Github Info').item.json['Github Branch'] }}",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "=Bearer {{ $('Set Github Info').item.json['Github Token'] }}"
            },
            {
              "name": "Content-Type",
              "value": "application/json"
            }
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={\n  \"sha\": \"{{ $json.sha }}\",\n  \"force\": false\n}",
        "options": {}
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        420,
        180
      ],
      "id": "3a29539c-dd3f-4092-9d36-84fe9d65c2bf",
      "name": "Update branch"
    },
    {
      "parameters": {},
      "type": "n8n-nodes-base.manualTrigger",
      "typeVersion": 1,
      "position": [
        -300,
        -60
      ],
      "id": "891f7a36-a17d-4c32-bd62-e68c8a0ae0a7",
      "name": "When clicking ‘Test workflow’"
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "c1ba4494-05cf-4c4f-8ec1-283083fbcaa4",
              "name": "Github Token",
              "value": "YOUR_GITHUB_PAT_TOKEN",
              "type": "string"
            },
            {
              "id": "3e65c520-9fcd-442a-adf3-2a0f273b149b",
              "name": "Github Repo",
              "value": "YOUR_GITHUB_REPO_NAME",
              "type": "string"
            },
            {
              "id": "49bf7a21-6fc2-4c8c-a229-1b2f41a4de71",
              "name": "Github Username",
              "value": "YOUR_GITHUB_USERNAME",
              "type": "string"
            },
            {
              "id": "c8cf6bad-5c28-4536-ac16-1442a4fdbd18",
              "name": "Github Branch",
              "value": "main",
              "type": "string"
            },
            {
              "id": "3fea08bc-032e-4194-9fd6-9e4de79e2fcf",
              "name": "Github Commit Update Message",
              "value": "Updating file1.txt and file2.txt",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        -120,
        -60
      ],
      "id": "ea97d057-fc19-49cc-a5fb-1ab0adbceacb",
      "name": "Set Github Info"
    },
    {
      "parameters": {
        "content": "## Push Multiple Files to GitHub Repo  \nA streamlined workflow for uploading multiple files to a GitHub repository via the GitHub REST API. This solution addresses a significant limitation of the native GitHub n8n node, which supports only single-file uploads.\n\nThis approach enables batch file operations, making it particularly valuable for automation scenarios that require simultaneous uploads of multiple files to your GitHub repositories.\n\n### Setup Instructions:\n1. Create a new GitHub Personal Access Token [here](https://github.com/settings/personal-access-tokens). In the \"Repository access\" section, select your repository and grant \"Read and write\" permissions under the \"Contents\" category.  \n2. Configure your GitHub information in the \"Set GitHub Info\" node.  \n3. Update the \"Create New Tree\" node with your filenames and content. You can add as many tree entries (files) as needed.",
        "height": 380,
        "width": 580
      },
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -960,
        -80
      ],
      "id": "afd1d74c-7d06-4e49-a906-a9d637ce8600",
      "name": "Sticky Note1"
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "0ddbab7f-7073-4568-9ca5-2b3799d4a87e",
              "name": "content",
              "value": "This is the content of your file #1.",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        60,
        -60
      ],
      "id": "d282fec1-0fd9-4956-95b4-0437ed67ff03",
      "name": "File 1"
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "0ddbab7f-7073-4568-9ca5-2b3799d4a87e",
              "name": "content",
              "value": "This is the content of your file #2.",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        240,
        -60
      ],
      "id": "426b3d80-c5af-4029-a4e7-b56b0af7601a",
      "name": "File 2"
    }
  ],
  "pinData": {},
  "connections": {
    "Get latest commit SHA": {
      "main": [
        [
          {
            "node": "Get base tree SHA",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get base tree SHA": {
      "main": [
        [
          {
            "node": "Create new tree",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Create new tree": {
      "main": [
        [
          {
            "node": "Create commit",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Create commit": {
      "main": [
        [
          {
            "node": "Update branch",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "When clicking ‘Test workflow’": {
      "main": [
        [
          {
            "node": "Set Github Info",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set Github Info": {
      "main": [
        [
          {
            "node": "File 1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "File 1": {
      "main": [
        [
          {
            "node": "File 2",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "File 2": {
      "main": [
        [
          {
            "node": "Get latest commit SHA",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "2920d785-d42a-4901-b5d9-6929ac62c132",
  "meta": {
    "instanceId": "ddfdf733df99a65c801a91865dba5b7c087c95cc22a459ff3647e6deddf2aee6"
  },
  "id": "RtTHLr1SAwIpntKr",
  "tags": []
}