简体   繁体   English

如何使用 Github API 推送代码?

[英]How to push code using Github API?

I want to push a directory to Github via nodejs app.我想通过 nodejs 应用程序将目录推送到 Github。 Here's what I currently do.这是我目前所做的。 I take username, password and new repository name from user.我从用户那里获取用户名、密码和新的存储库名称。 Then, I create new repository via Github API( https://developer.github.com/v3/repos/#create ).然后,我通过 Github API( https://developer.github.com/v3/repos/#create )创建新的存储库。 Now I want to push some specific code to this repository.现在我想将一些特定的代码推送到这个存储库。 I can't use node.js child process (git push origin master), because that requires username and password.我不能使用 node.js 子进程(git push origin master),因为这需要用户名和密码。 How can I push code to Github via API.如何通过 API 将代码推送到 Github。 (And if via command line, then without entering password manually) (如果通过命令行,则无需手动输入密码)

To skip the password on each commit you need to tell the git to store the credential in a separate place.要在每次提交时跳过密码,您需要告诉 git 将凭据存储在单独的位置。 This can be done by using the following command:这可以通过使用以下命令来完成:

git config --global credential.helper cache

This will store the password for 15 minutes .这会将密码存储15 分钟 If you wish you can extend this time by specifying the amount of duration in milliseconds:如果您愿意,可以通过以毫秒为单位指定持续时间来延长此时间:

git config --global credential.helper "cache --timeout=3600"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM