我创建了一个新的本地Git存储库:
~$ mkdir projectname
~$ cd projectname
~$ git init
~$ touch file1
~$ git add file1
~$ git commit -m 'first commit'
有没有任何git命令来创建一个新的远程回购,并从这里将我的提交推到GitHub ?我知道打开浏览器去创建一个新的存储库并不是什么大问题,但是如果有一种方法可以从CLI实现这一点,我会很高兴。
我读了大量的文章,但没有一篇提到如何使用git命令从CLI创建远程回购。Tim Lucas的一篇不错的文章“设置一个新的远程git存储库”是我找到的最接近的文章,但是GitHub不提供shell访问。
这可以用三个命令来完成:
curl -u 'nyeates' https://api.github.com/user/repos -d '{"name":"projectname","description":"This project is a test"}'
git remote add origin git@github.com:nyeates/projectname.git
git push origin master
(v3 Github API更新)
这些命令的解释…
创建github回购
curl -u 'nyeates' https://api.github.com/user/repos -d '{"name":"projectname","description":"This project is a test"}'
curl is a unix command (above works on mac too) that retrieves and interacts with URLs. It is commonly already installed.
"-u" is a curl parameter that specifies the user name and password to use for server authentication.
If you just give the user name (as shown in example above) curl will prompt for a password.
If you do not want to have to type in the password, see githubs api documentation on Authentication
"-d" is a curl parameter that allows you to send POST data with the request
You are sending POST data in githubs defined API format
"name" is the only POST data required; I like to also include "description"
I found that it was good to quote all POST data with single quotes ' '
定义推到哪里
git remote add origin git@github.com:nyeates/projectname.git
在github上添加连接(远程)回购的位置和存在的定义
“origin”是git用来表示源代码来源的默认名称
技术上没有来自github,但现在github回购将记录的来源
“git@github.com:nyeates”是一个SSH连接,它假设你已经在github上设置了一个可信的SSH密钥对。
将本地回购推到github
git push origin master
从主本地分支推送到原始远程(github)
我用GitHub和BitBucket的REST api写了一个漂亮的脚本,叫做Gitter:
https://github.com/dderiso/gitter
BitBucket都:
gitter -c -r b -l javascript -n node_app
GitHub:
gitter -c -r g -l javascript -n node_app
-c =创建新的repo
-r = repo provider (g = GitHub, b = BitBucket)
-n =命名回购
-l = (optional)设置repo中应用程序的语言
有关创建令牌的说明,请转到这里。这是您将键入的命令(从回答的日期开始)。(替换所有CAPS关键字):
curl -u 'YOUR_USERNAME' -d '{"scopes":["repo"],"note":"YOUR_NOTE"}' https://api.github.com/authorizations
输入密码后,您将看到下面包含您的令牌。
{
"app": {
"name": "YOUR_NOTE (API)",
"url": "http://developer.github.com/v3/oauth/#oauth-authorizations-api"
},
"note_url": null,
"note": "YOUR_NOTE",
"scopes": [
"repo"
],
"created_at": "2012-10-04T14:17:20Z",
"token": "xxxxx",
"updated_at": "2012-10-04T14:17:20Z",
"id": xxxxx,
"url": "https://api.github.com/authorizations/697577"
}
您可以随时到这里撤销您的令牌