18

It's my understanding that to create a personal repository on the command line, using the GitHub v3 API, one can do this (replacing USERNAME and REPONAME appropriately):

curl -u 'USERNAME' https://api.github.com/user/repos -d '{"name":"REPONAME"}'

The user then enters their username and password, and GitHub will create a new empty repository at "github.com/USERNAME/REPONAME".

My question is, how do I create an organization-owned repository via command line? I tried replacing USERNAME with the organization's name, and it prompted me for the 'host password'. I own the organization so I entered my password but I got "Bad credentials". Does this method not work for organization-owned repositories? Or am I doing something wrong?

MD XF
  • 7,860
  • 7
  • 40
  • 71

3 Answers3

17

With the new github cli, it is as simple as:

gh repo create ORGNAME/REPONAME
greg hor
  • 682
  • 6
  • 17
6

To create a repository under an organisation you should send the request to the POST /orgs/:org/repos endpoint rather than /user/repos. Your user shouldn't need any extra permissions or scopes over what is required to create a user repository, but the user must be a member of :org:

Create

Create a new repository for the authenticated user. (Currently not enabled for Integrations)

POST /user/repos

Create a new repository in this organization. The authenticated user must be a member of the specified organization.

POST /orgs/:org/repos

(From https://developer.github.com/v3/repos/#create)

kfb
  • 6,252
  • 6
  • 40
  • 51
  • 2
    For clarification, do I keep the `:` in the `:org`? For example, if my organization name was 'foo' would the request be `POST /orgs/:foo/repos` or `POST /orgs/foo/repos`? – MD XF Nov 09 '16 at 18:49
  • 2
    You do not keep the colon. It only designates it as a variable. You can see an example of a call made to the same endpoint here: http://stackoverflow.com/a/19577228/1639983 EDIT: I know the call isn't doing the same thing, but the endpoint is still the same. – Holden Lewis Nov 09 '16 at 19:28
5

Just for completeness: Example for Git Api v3:

curl -u USERNAME https://api.github.com/orgs/ORGNAME/repos -d '{"name":"NAME_OF_REPO", "description":"SOME_DESCRIPTION", "private": true, "has_issues": true, "has_projects": true, "has_wiki":false }'
Markus W.
  • 307
  • 3
  • 10