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.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…