Skip to content

Instantly share code, notes, and snippets.

@lazywithclass
Created February 20, 2017 02:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lazywithclass/fbcfc277ffee7479be5654303f48c494 to your computer and use it in GitHub Desktop.
Save lazywithclass/fbcfc277ffee7479be5654303f48c494 to your computer and use it in GitHub Desktop.
Create a private github repo in an organisation using the CLI

Create a private github repo in an organisation using the CLI

Today I've had some fun trying to understand how to that, as I couldn't find any example around here we go.

If your user has admin rights in an organisation then you can create a private repository, to find out if you're in such position just execute

curl -u "$user:$token" https://api.github.com/orgs/$organisation/teams

which should return an array of teams

[{
  ...
}, {
  "name": "devs",
  "id": 123456,
  "slug": "devs",
  "description": null,
  "permission": "admin",
  "url": "https://api.github.com/teams/123456",
  "members_url": "https://api.github.com/teams/123456/members{/member}",
  "repositories_url": "https://api.github.com/teams/123456/repos"
}, {
  ...
}]

If permission is "admin" then you're fine and you can use the id value for the next call

curl -u "$user:$token" https://api.github.com/orgs/$organisation/repos -d '{
  "name": "your-repo-name", 
  "private": true, 
  "team_id": 123456
}'

...and that's it. Pretty straightforward, yes I know, but still it took me over 2 hours to figure it out.

Here are the links to the relevant APIs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment