:bulb: You can create a GitHub remote repository entirely from the command line using curl and the GitHub REST API — no browser required.

[01] Prerequisites

To create a remote repository via the CLI, you need:

  • curl installed on your system
  • A GitHub Personal Access Token (PAT) with repo scope
  • Your GitHub username

The GitHub REST API endpoint used is:

1
POST https://api.github.com/user/repos

[02] Issue a Personal Access Token

Navigate to: User Profile → Settings → Developer settings → Personal access tokens

Steps to generate a new token:

  1. Click Generate new token.
  2. Under Select scopes, check the entire repo section.
  3. Click Generate token and copy the value — it is shown only once.

To regenerate an existing token: select the token name, then click Regenerate token.

Figure 1. Navigate to Developer Settings

doit_django_09

Figure 2. Personal access tokens list

doit_django_02

Figure 3. Select repo scope when generating token

doit_django_03

Figure 4. Copy the generated token

doit_django_04

[03] Using the API

Reference: GitHub API — Create a repository for the authenticated user

3-1. Verify the API connection

Before creating a repo, confirm your token is valid by fetching your user info:

1
curl -i -u cmaven:${user_token} https://api.github.com/user

Expected response (truncated):

1
2
3
4
5
HTTP/1.1 200 OK
Server: GitHub.com
Date: Thu, 25 Aug 2022 03:01:21 GMT
Content-Type: application/json; charset=utf-8
...

A 200 OK response confirms the token works. A 401 Unauthorized means the token is invalid or expired.

3-2. Create the remote repository

Send a POST request with the repository name and visibility:

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 / macOS bash
curl -i -u cmaven:${user_token} https://api.github.com/user/repos -d '{"name":"doit_django", "private":"true"}'
Field Description
name Repository name to create
private true = private repo, false = public repo

Figure 5. Successful creation response

doit_django_08

Figure 6. New repository visible on GitHub

doit_django_07

3-3. Troubleshooting

Symptom Likely cause Fix
401 Unauthorized Token invalid or expired Regenerate the PAT and retry
422 Unprocessable Entity Repository name already exists Choose a different name value
curl: command not found curl not installed Install via apt install curl or choco install curl

Note: GitHub deprecated password-based authentication for API calls. Always use a PAT or OAuth token.