ravindra devagiri
ravindra devagiri

Reputation: 41

How to create and push multiple files to git repository using node js code

I have a code where I am downloading lot of files from S3/Azure. I want to push them to new repository in github using NodeJS code. Tried simpleGit module but it didnt workout. Here is the thing which I want to do - Create a new repository in github if not exists already - create files on fly with data I have and add them git repository. - commit those changes - push them to remote

Tried SimpleGit, NodeGit...but none of them have proper examples to do this task.

Upvotes: 1

Views: 2218

Answers (1)

Arfost
Arfost

Reputation: 506

From what you are saying, you are trying to create a new repo on github before pushing to it. I think your issue is that you can't use git to create a github repo directly. They are two different things. For creating a new github repo you should use the github API https://developer.github.com/v3/repos/#create

When your repository is done, you should then be able to push to it with git and the libs you mentionned should do the trick.

When the repository is created follow the step here but with the equivalent commands from simpleGit (or any other lib, but this is the first you cited)

https://help.github.com/en/articles/adding-an-existing-project-to-github-using-the-command-line

Step 4 to the end (but don't do it directly, that's just to show what is needed to do)

And from simpleGit documentation

https://www.npmjs.com/package/simple-git#starting-a-new-repo

This example should do exactly what you need. You can try to find which command correspond to which of the step describe in the github doc.

Upvotes: 1

Related Questions