我有一个非常奇怪的问题与git和github。当我试着推的时候,我得到:

git push -u origin master
ERROR: Repository not found.
fatal: The remote end hung up unexpectedly

我添加了遥控器:

git remote add origin git@github.com:account-name/repo-name.git

什么好主意吗?


当前回答

如果您确定已经拥有对这个存储库的SSH访问权限。

Do

git clone https://myusername@github.com/path_to/myRepo.git

其他回答

Normally it happens because the project is private and you have not rights to write it. I had the same "problem" a few times, and it was for that reason. If the project it is yours, just create a private and a public key following this link: https://docs.github.com/en/github/authenticating-to-github/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent and add them to the "SSH and Key" section on gitHub, then you will be able to push to the repo. In the other hand if the project it is not your, ask the owner to give you the rights for it.

如果你的repo之前工作正常,突然弹出这个错误,最有可能的原因是你的git被认证为其他用户,没有访问存储库的权限。因此,为了进行推送,您所需要做的就是在git命令中指定正确的用户名和密码。所以,一个github回购的推命令看起来像:

git push https://youruser:password@github.com/user/reponame.git

用户名和密码需要进行url转义,因此@应该被%40取代,等等。

如果使用私有存储库检查连接用户,则该用户必须具有使用存储库的权限。

有类似的问题。问题的根源是我遵循了一些关于向Github添加新存储库的在线教程。

只要去Github,创建一个新的repo,它会要求你添加一个README,不要添加它。创建它,你会得到如何推送的指导。

它类似于接下来的两行:

git remote add origin https://github.com/YOUR_USER/your-repo.git
git push -u origin master

当我试图推到我以前访问过的私人回购时,我遇到了这个错误。问题不在于回购是私有的还是公共的,问题在于Github API现在使用个人令牌而不是用户名和密码进行身份验证和授权。

以下方法解决了我的问题:

删除远程原点:git远程删除原点 生成一个个人代币:你可以在Github Docs中找到说明。 重新添加原点,但使用您的用户名和生成的令牌:

git远程添加origin https://USERNAME:GENERATED_TOKEN@github.com/username/reponame.git

注意: 如果在创建和使用令牌一段时间后遇到此问题,请确保令牌没有过期。如果是,重新生成它,并确保对使用旧令牌的回购重复第3步(如上所述)。此外,如果您更改了令牌,请为使用旧令牌的repo重做步骤3。