Add An Existing Repo to Github via CLI

If you’d like to push an already existing git repository to github then you can easily create the repository from the cli and begin the foundations of interacting with remote repos programmatically. First, you need a personal access token and if you do not yet have one then perform the following:

  • Access your github account settings
    • Developer Settings
    • Personal access tokens
      • Generate new token

Be sure to save/download the token, as you will be unable to access it in the future. Once the token has been generated use it in the following curl command to create the desired repo replacing <name> with the desired repo name:

curl -X POST \
  -H "Accept: application/vnd.github+json" \
  -H "Authorization: token <token>" \
  --data '{"name":"<name>"}' \
  https://api.github.com/user/repos

Afterwards, don’t forget to add the remote to your repo with git remote add origin <name>. To see more options for this and other commands visit this page.

github  cli  curl 

See also