-4

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: enter image description here

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.

Community
  • 1
  • 1
geoyws
  • 2,457
  • 26
  • 36
  • Not an authoritive answer, but probably because otherwise every typo in the url could make a repository, leading into lots of unwanted extra repositories – Ikke Jun 18 '14 at 07:48
  • @Leigh https://developer.github.com/guides/getting-started/#create-a-repository You can see the curl command there. – geoyws Jun 18 '14 at 09:19

1 Answers1

3

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.

Chronial
  • 55,303
  • 13
  • 76
  • 85
  • Alright managed to create it via hub. Seems like the best way to go about it for now. They should've just built it in. – geoyws Jun 18 '14 at 11:49
  • 4
    @Geoyws, you're missing the point. Git and GitHub are different things. GitHub did not create Git. GitHub is built *on top of* Git. The `git` command line tool was not created by GitHub, but by many developers around the world, largely working for free, and therefore has no support for GitHub's proprietary features. `hub` is GitHub's way of adding proprietary features to the command line. – Chris Jun 18 '14 at 12:08