为什么GitHub不允许使用命令行开箱即用创建我们的存储库? [英] Why does GitHub not let us create our repositories using the command line out-of-the-box?

查看:373
本文介绍了为什么GitHub不允许使用命令行开箱即用创建我们的存储库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果GitHub将它建成Git Shell,不是很好吗?



显然具有授权令牌:

  $ curl -i -H'授权:token 5199831f4dd3b79e7c5b7e0ebe75d67aa66e79d4'\ 
-d' {\
name:blog,\
auto_init:true,\
private:true,\
gitignore_template: nanoc\
}'\
https://api.github.com/user/repos

注意:根据 developer.github.com/v3 。我们可以省略一切,只需键入:

  $ curl -i -H'授权:token 5199831f4dd3b79e7c5b7e0ebe75d67aa6e79d4'\ 
-d'{\
name:new_repo_name,\
}'\
https://api.github.com/user/repos

问题是...输入那个长令牌(你不能CTRL-V在cmd)




$ b 我发现中心是一个很好的解决方案。只需安装它,导航到您的github repo文件夹,并创建如下的repo:

  hub create new_repo_name 

我们已经准备好提交和推送了。没有投诉。

解决方案

关于你的第一个问题:这不是github的限制,而是git。 Git不是专门为github设计的,因此不支持推送到不存在的仓库。我想github可以在服务器端破解,但这只是创建一个repo为每一个错字等,如Ikke指出。



如果你想要更好的命令 - 您可以使用github的 hub 工具: https:// github.com/github/hub 。使用它,你可以用 hub create

$

创建一个repo。或者,你可以自己创建一个小shell脚本其中包含所有必需的代码,只需将存储库名称作为参数。


Wouldn't it be nice if GitHub built this into Git Shell?

Apparently Stack Overflow says we have to use cURL to do it.

curl -u 'USER' https://api.github.com/user/repos -d '{"name":"REPO"}'
# Remember replace USER with your username and REPO with your repository/application name!
git remote add origin git@github.com:USER/REPO.git
git push origin master

But it doesn't work for me. I get a 401 Unauthorized if I use this method:

Note: --cacert is just to include a cert for SSL in my root directory

Hrm. Okay. So then I found out that the official docs do it with an authorization token:

$ curl -i -H 'Authorization: token 5199831f4dd3b79e7c5b7e0ebe75d67aa66e79d4' \
    -d '{ \
        "name": "blog", \
        "auto_init": true, \
        "private": true, \
        "gitignore_template": "nanoc" \
      }' \
    https://api.github.com/user/repos

Note: only "name" is required in the -d JSON http body according to developer.github.com/v3. We can leave out everything else and just type:

$ curl -i -H 'Authorization: token 5199831f4dd3b79e7c5b7e0ebe75d67aa66e79d4' \
    -d '{ \
        "name": "new_repo_name", \
      }' \
    https://api.github.com/user/repos

Problem is... typing in that long token (you can't CTRL-V in cmd) is going to defeat the purpose of using the CLI in the first place.

EDIT

I found hub to be a very good solution. Just install it, navigate to your github repo folder, and create a repo like this:

hub create new_repo_name

And we're done and ready for commits and pushes. No complaints so far.

解决方案

Regarding your first question: This is not a "restriction" by github, but by git. Git is not specifically designed for github and thus has no support for pushing to non-existent repositories. I think github could hack that in on the server side, but that would just create a repo for every typo etc, as Ikke pointed out.

If you want nicer command-line support, you can use github’s hub tool: https://github.com/github/hub. Using that, you can create a repo with hub create.

Alternatively you could just create a small shell script yourself that contains all the required code and just takes the repository name as parameter.

这篇关于为什么GitHub不允许使用命令行开箱即用创建我们的存储库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆