How do i upload a folder that contains all my code files to my Github repo using Github's REST API programmatically? #83252
-
Select Topic AreaQuestion BodyHow do I upload a folder that contains all my code files to my Github repo using Github's REST API programmatically? Can anyone help me do that in JavaScript with Node.js? Currently, when I try to run my code, it only uploads files, but how do I upload a folder instead? I don't want to upload files one by one. Any idea what to do? |
Beta Was this translation helpful? Give feedback.
Replies: 12 comments 16 replies
-
|
Probably you have to loop through all files in the folder and upload them one by one. |
Beta Was this translation helpful? Give feedback.
-
|
@DozenLimeStone I did this but then it created a myfoldername.zip file in my GitHub repo with a base64 string like "YW1vZ3VzLmh0bWw=" instead of my code files my code: |
Beta Was this translation helpful? Give feedback.
-
|
this is not actually answered; following from isaacs/github#199 to here how can do Multi file operations in a single commit through the contents API. #199 ? |
Beta Was this translation helpful? Give feedback.
-
|
did you try drag & drop ? |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
|
go vs code do |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
|
`` |
Beta Was this translation helpful? Give feedback.
-
|
نه |
Beta Was this translation helpful? Give feedback.
-
Carlyluminatti and sub files |
Beta Was this translation helpful? Give feedback.
-
|
Hello everyone,
I hope this message finds you energized and ready for some great news! I’m thrilled to announce a new development that will make uploading your project folders to your GitHub repository easier and more efficient than ever before. For all those who have been searching for a streamlined way to upload entire folders—rather than uploading files one by one—your solution is here!
Get ready to experience a smoother workflow with programmatic folder uploads using GitHub’s REST API and Node.js. This enhancement is designed to simplify your process and boost productivity, so you can focus more on coding and less on manual uploads.
Stay tuned for more updates and details on how you can take advantage of this new approach. I can’t wait to see how this empowers our community and sparks even greater innovation!
Best regards,
Michael
…________________________________
From: Carly BigEagle-Whiteman ***@***.***>
Sent: Sunday, March 1, 2026 4:42 AM
To: community/community ***@***.***>
Cc: yYargadriod777 ***@***.***>; Manual ***@***.***>
Subject: Re: [community/community] How do i upload a folder that contains all my code files to my Github repo using Github's REST API programmatically? (Discussion #83252)
Select Topic Area
Question
Body
How do I upload a folder that contains all my code files to my Github repo using Github's REST API programmatically? Can anyone help me do that in JavaScript with Node.js?
Currently, when I try to run my code, it only uploads files, but how do I upload a folder instead? I don't want to upload files one by one. Any idea what to do?
async function upload() {
const message = 'amogus';
const content = 'aaaaa';
const owner = 'MY-USERNAME';
const repo = 'MY-REPO-NAME';
const path = 'my-project';
const auth = '{MY ACCESS TOKEN HERE}';
const existingFile = await (await fetch(
`https://api.github.com/repos/${owner}/${repo}/contents/${path}`,
{
method: 'GET',
headers: {
Accept: 'application/vnd.github+json',
Authorization: `Bearer ${auth}`
}
}
)).json();
await (await fetch(
`https://api.github.com/repos/${owner}/${repo}/contents/${path}`,
{
method: 'PUT',
headers: {
Accept: 'application/vnd.github+json',
Authorization: `Bearer ${auth}`
},
body: JSON.stringify({
message: message,
content: btoa(content),
sha: existingFile.sha,
}),
}
)).json();
}
Carlyluminatti and sub files
—
Reply to this email directly, view it on GitHub<#83252 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/B3M67BUQQMJNY7T4RCCMQ4D4OQH3FAVCNFSM6AAAAAB2B235KOVHI2DSMVQWIX3LMV43URDJONRXK43TNFXW4Q3PNVWWK3TUHMYTKOJWGA2DEMA?target=https://github.com>.
You are receiving this because you are subscribed to this thread.Message ID: ***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
|
async function upload() {
const message = "amogus";
const content = "aaaaa";
const owner = "MY-USERNAME";
const repo = "MY-REPO-NAME";
const path = "my-project/file.txt"; // MUST include a filename
const auth = "{MY ACCESS TOKEN HERE}";
// Safe base64 encoding
const encoded = btoa(unescape(encodeURIComponent(content)));
// Check if file exists
const getRes = await fetch(
`https://api.github.com/repos/${owner}/${repo}/contents/${path}`,
{
method: "GET",
headers: {
Accept: "application/vnd.github+json",
Authorization: `Bearer ${auth}`,
},
}
);
let sha = undefined;
if (getRes.ok) {
const existing = await getRes.json();
sha = existing.sha; // required for updating
}
// Create or update file
const putRes = await fetch(
`https://api.github.com/repos/${owner}/${repo}/contents/${path}`,
{
method: "PUT",
headers: {
Accept: "application/vnd.github+json",
Authorization: `Bearer ${auth}`,
},
body: JSON.stringify({
message,
content: encoded,
sha, // include only if updating
}),
}
);
const result = await putRes.json();
console.log(result);
…________________________________
From: Carly BigEagle-Whiteman ***@***.***>
Sent: Sunday, March 1, 2026 4:42 AM
To: community/community ***@***.***>
Cc: yYargadriod777 ***@***.***>; Manual ***@***.***>
Subject: Re: [community/community] How do i upload a folder that contains all my code files to my Github repo using Github's REST API programmatically? (Discussion #83252)
Select Topic Area
Question
Body
How do I upload a folder that contains all my code files to my Github repo using Github's REST API programmatically? Can anyone help me do that in JavaScript with Node.js?
Currently, when I try to run my code, it only uploads files, but how do I upload a folder instead? I don't want to upload files one by one. Any idea what to do?
async function upload() {
const message = 'amogus';
const content = 'aaaaa';
const owner = 'MY-USERNAME';
const repo = 'MY-REPO-NAME';
const path = 'my-project';
const auth = '{MY ACCESS TOKEN HERE}';
const existingFile = await (await fetch(
`https://api.github.com/repos/${owner}/${repo}/contents/${path}`,
{
method: 'GET',
headers: {
Accept: 'application/vnd.github+json',
Authorization: `Bearer ${auth}`
}
}
)).json();
await (await fetch(
`https://api.github.com/repos/${owner}/${repo}/contents/${path}`,
{
method: 'PUT',
headers: {
Accept: 'application/vnd.github+json',
Authorization: `Bearer ${auth}`
},
body: JSON.stringify({
message: message,
content: btoa(content),
sha: existingFile.sha,
}),
}
)).json();
}
Carlyluminatti and sub files
—
Reply to this email directly, view it on GitHub<#83252 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/B3M67BUQQMJNY7T4RCCMQ4D4OQH3FAVCNFSM6AAAAAB2B235KOVHI2DSMVQWIX3LMV43URDJONRXK43TNFXW4Q3PNVWWK3TUHMYTKOJWGA2DEMA?target=https://github.com>.
You are receiving this because you are subscribed to this thread.Message ID: ***@***.***>
|
Beta Was this translation helpful? Give feedback.
@xts-bit Well then recursively get them all :) The best other thing you can do is to compress them into one file and send it.