:bulb: This note explains how to create a remote repository from the CLI without using the GitHub web UI.

[01] Prerequisites

  • Use curl to create the remote repository via the GitHub API.
  • To call the GitHub API remotely, a User Token must be issued from GitHub.

[02] Issue a Token

User Profile → Settings → Developer settings → Personal access tokens

  • To create a new token: click Generate new token.
    • For Select scopes, check the entire repo section.
  • To regenerate an existing token: select the token name, then click Regenerate token.
  • The generated token will be used for API calls.

Reference screenshots:

doit_django_09

doit_django_02

doit_django_03

doit_django_04

[03] Using the API

:small_blue_diamond:Reference: GitHub API — Create an organization repository

3-1. Verify the API works

1
2
3
4
5
6
7
8
9
10
11
12
curl -i -u cmaven:${user_token} https://api.github.com/user

# example
E:\Coding\Python\doit_djngo>curl -i -u cmaven:${user_token} https://api.github.com/user
HTTP/1.1 200 OK
Server: GitHub.com
Date: Thu, 25 Aug 2022 03:01:21 GMT
Content-Type: application/json; charset=utf-8
Content-Length: 1264
Cache-Control: private, max-age=60, s-maxage=60
Vary: Accept, Authorization, Cookie, X-GitHub-OTP
# ...

3-2. Create the remote repository

  • name is the repository name to create.
  • When private is set to true, the repository is created as private.
1
2
3
4
5
# Windows cmd
curl -i -u cmaven:${user_token} https://api.github.com/user/repos -d "{\"name\":\"doit_django\", \"private\":\"true\"}"

# Linux bash shell
curl -i -u cmaven:${user_token} https://api.github.com/user/repos -d '{"name":"doit_django", "private":"true"}'

Creation example:

doit_django_08

Created repository view:

doit_django_07