"git remote add"不能创建仓库。

3

我想从我的shell中添加远程仓库,但失败了。我已经登录并在我的本地仓库中。所以我输入了以下内容:

% 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)

看起来仓库已经创建了,但是我在我的Github账户中没有看到新的仓库。当我尝试检查远程仓库(或将任何内容推送到那里)时,它会抛出一个错误:

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

我尝试谷歌类似的问题,但找不到答案。有人知道我可能错过了什么吗?


如果你想在GitHub上创建一个仓库,除了使用他们的图形界面(就像我经常喜欢的方式),还可以尝试一下Hub CLI https://hub.github.com/。 - Joshua
你好,欢迎来到SO。请参考当有人回答你的问题时,你可以做什么 - Daemon Painter
1
@konekoya hub 已被替换为 gh 作为新的官方 GitHub 命令行界面。https://cli.github.com/ - jessehouwing
https://stackoverflow.com/search?q=%5Bgit%5D+%22git+remote+add%22+create - phd
2个回答

8

git remote add 不会 "在 Github 上创建仓库",它只是将本地仓库与已存在于 Github 上的远程仓库进行连接。

如果 example.git 在 Github 上不存在,你需要先创建它(例如通过 Github 网站创建一个空的 example 仓库)。

之后,你可以使用普通的 Git 命令(如 pushpullremote show ...)。


谢谢,你说得对! - Stunt-man-mike

3
如果你想从命令行创建一个repo,你可以使用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

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接