Git GitHub无法推送到远程(origin)。

10
我可能漏看了什么,但我确信已经检查过所有内容, 我 fork 了一个 repo 并在我的系统上克隆了它, 做了一些更改, 提交后 执行了 git push origin master 它显示:
fatal: remote error: 
  You can't push to git://github.com/my_username/my_repo.git
  Use git@github.com:my_username/my_repo.git

我有点不明白,

我尝试输入以下命令:

git remote add origin https://github.com/my_username/my_repo.git

但是它返回了:

fatal: remote origin already exists.

我不明白为什么会出现这种情况,请帮忙解答。

3个回答

23

链接地址为

git://github.com/my_username/my_repo.git

git:// 只提供只读访问,如侧面所述。

enter image description here

然而,

git@github.com:my_username/my_repo.git

提供了在该网站中所提到的读写访问权限

enter image description here

尽管https://github.com/my_username/my_repo.git也具有读写访问权限,但在您的情况下它无法工作,因为您试图创建一个具有相同名称的新远程而不是重置它。正确的语法如下所述:

git remote set-url origin git@github.com:my_username/my_repo.git

以及

git remote set-url origin https://github.com/my_username/my_repo.git

也可以工作。


5

git remote set-url origin git@github.com:my_username/my_repo.git

翻译为:

git remote set-url origin git@github.com:我的用户名/我的仓库.git


这个可以,时间限制结束后我会接受这个答案。但是,你能解释一下问题是什么吗?非常感谢。 - pahnin
我认为https URL仅适用于只读存储库获取。但是git@github也提供了写入和读取权限。 - vincent mathew

0
这不起作用的原因是,您选择的 git:// 协议仅在 Github 上配置为读取访问(因为它只支持匿名写入访问而没有访问限制)。
Github 支持使用 ssh(git@github.com...)和 https 写入访问存储库。
您的第二个命令失败了,因为当您克隆时,git 已经创建了一个名为 origin 的远程。因此,如果您想添加另一个远程存储库,您必须给出另一个名称。

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