git github 无法推送到原点

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11101203/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 07:05:41  来源:igfitidea点击:

git github cannot push to origin

gitgithubpush

提问by pahnin

I may be missing something, but I'm sure that I've checked everything, I forked a repo and cloned it on my system, made some changes after commiting did git push origin master

我可能遗漏了一些东西,但我确定我已经检查了所有内容,我创建了一个 repo 并将其克隆到我的系统上,在提交后做了一些更改 git push origin master

it says

它说

fatal: remote error: 
  You can't push to git://github.com/my_username/my_repo.git
  Use [email protected]:my_username/my_repo.git

Am I missing something? then I tried git remote add origin https://github.com/my_username/my_repo.git

我错过了什么吗?然后我试过了 git remote add origin https://github.com/my_username/my_repo.git

it returned

它回来了

fatal: remote origin already exists.

致命:远程源已经存在。

I dont understand why this is hapenning, pls help

我不明白为什么会这样,请帮忙

回答by vincent mathew

The url with

网址与

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

git:// Only gives read only access as mentioned in the side too..

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

enter image description here

在此处输入图片说明

Whereas,

然而,

[email protected]:my_username/my_repo.git

gives read and write access as mentioned in site

提供站点中提到的读写访问权限

enter image description here

在此处输入图片说明

Though, https://github.com/my_username/my_repo.gitalso has read and write access but it was not working in your case because you trying to create a new remote with the same name instead of resetting it. The correct syntax as mentioned was

虽然,https://github.com/my_username/my_repo.git也有读写访问权限,但它在您的情况下不起作用,因为您试图创建一个具有相同名称的新遥控器而不是重置它。提到的正确语法是

git remote set-url origin [email protected]:my_username/my_repo.git

git remote set-url origin [email protected]:my_username/my_repo.git

And

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

would also work.

也会工作。

回答by Yuval Adam

git remote set-url origin [email protected]:my_username/my_repo.git

git remote set-url origin [email protected]:my_username/my_repo.git

回答by dunni

The reason why this does not work is, that the git:// protocol, which you chose for cloning, is only configured for read access at Github (since it only would support anonymous write access without access restrictions).
Github supports both ssh ([email protected]...) and https for write access to repositories.

这不起作用的原因是,您选择用于克隆的 git:// 协议仅在 Github 上配置为读取访问(因为它仅支持没有访问限制的匿名写入访问)。
Github 支持 ssh ([email protected]...) 和 https 对存储库的写访问。

Your second command fails, because when you clone, git already creates a remote named origin. So if you want to add another remote repository, you have to give another name.

你的第二个命令失败了,因为当你克隆时,git 已经创建了一个远程命名的 origin。所以如果你想添加另一个远程仓库,你必须给另一个名字。