我有本地工作副本SourceTree。和所有的操作工作得很好,我可以简单的获取,推,拉等通过SourceTree。我只需要在SourceTree中不存在的force push。

我打开终端使git按-f

remote: Repository not found.
fatal: repository 'https://github.com/MyRepo/project.git/' not found

我不确定会有什么问题。


当前回答

在我的情况下,上述解决方案都不起作用。

我通过将remote.origin.url从https切换到ssh来解决这个问题:

验证git配置:

git config --list

应该是这样:

...
remote.origin.url=https://github.com/ORG/repo-name.git
...

使用SSH更新remote.origin.url:

git remote set-url origin git@github.com:ORG/repo-name.git

其他回答

因为您可能没有首先将远程git存储库标识到您的终端。

git remote set-url origin https://github.com/MyRepo/project.git

然后,

git add .
git commit -m "initial commit"
git push origin master

当存储库、团队名称或用户名更改时,就会发生这种情况。 有一个解决方案(我知道):恢复存储库名称。

增加“个人访问令牌”

自2021年以来,Github支持PAT而不是名称/密码(阅读这里如何创建和使用一个),所以我们只是把它添加到远程起源。

在Windows上

访问。git文件夹,打开配置文件进行编辑。如。vim配置。 将URL更改为 https://github.com/ <用户名> / < repo_name > . 来 https:// [personal-access-token] @github.com/ <用户名> / < repo_name > . 其中[personal-access-token]是你在github创建的PAT散列。 保存配置文件,现在推送应该可以工作了。

快捷方式:

git remote remove origin
git remote add origin https://[personal-access-token]@github.com/username/repo_name.git

更新

生成令牌时,如果希望令牌长时间工作,请选择“No expiration”。

如果您正在使用访问密钥,请在创建访问密钥时给予适当的权限(我尝试了所有权限,它可以工作)

我看到了这个致命的问题:当人们尝试在免费层上从私人GitHub帐户中推拉时,存储库现在更经常地发现错误。以下是最常见的解决方案:

您没有验证 您的密码已更改 你不是合作者 不正确的大小写或拼错的单词 已删除git存储库

Windows凭证管理器?

有时Windows凭证管理器会缓存你的u/p,并在幕后传递它。如果您最近更改了密码,或者使用了不同的用户名,您可能需要进入凭据管理器并清除GitHub的现有条目。