'git remote add' doesn't create repo

Viewed 542

I want to add remote repository from my shell but fail. I'm logged in and I'm in my local repository. So I enter this:

% git remote add origin https://github.com/<username>/example.git
% git remote -v
origin  https://github.com/<username>/example.git (fetch)
origin  https://github.com/<username>/example.git (push)

So it seems that the repo has been created. But I see no new repo in my github account. And when I try to inspect the remote (or push anything there) it throws an error:

% git remote show origin
remote: Repository not found.
fatal: repository 'https://github.com/<username>/example.git/' not found

I tried googling similar questions but couldn't find the answer. Does anyone know what I might be missing?

2 Answers

git remote add does not "create the repo on github", it only links your local repo to an (existing) remote repo on github.

If example.git does not exist on github, you need to first create it (e.g : create an empty example repo through github's website).

After that, your regular git commands will work (push, pull, remote show ...).

If you want to create a repo from the commandline, you can use the GitHub CLI.

> gh repo create

Usage:  gh repo create [<name>] [flags]

Flags:
  -y, --confirm              Confirm the submission directly
  -d, --description string   Description of repository
      --enable-issues        Enable issues in the new repository (default true)
      --enable-wiki          Enable wiki in the new repository (default true)
  -h, --homepage string      Repository home page URL
      --internal             Make the new repository internal
      --private              Make the new repository private
      --public               Make the new repository public
  -t, --team string          The name of the organization team to be granted access
  -p, --template string      Make the new repository based on a template repository
Related