Creating a Git Remote Repository from a Local Host
This note explains how to create a remote repository from the CLI without using the GitHub web UI.
[01] Prerequisites
- Use
curlto create the remote repository via theGitHub 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
reposection.
- For Select scopes, check the entire
- To regenerate an existing token: select the token name, then click
Regenerate token. - The generated token will be used for API calls.
Reference screenshots:




[03] Using the API
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
-
nameis the repository name to create. - When
privateis set totrue, 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:

Created repository view:
