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

我打开终端使git按-f

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

我不确定会有什么问题。


当前回答

禁用GIT证书对我有帮助:

git config --global --unset credential.helper

其他回答

在我的情况下,我需要在Linux上使用Ctrl + H打开目录来查看隐藏的文档,所以我进入Git配置并在URL中取出。Git。

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

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

然后,

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

在Windows上:

进入。git文件夹 使用记事本或任何其他编辑器打开“配置”文件 将您的URL从https://github.com/username/repo_name.git更改 https://username: password@github.com/username/repo_name.git

保存并推送代码,它将工作。

增加“个人访问令牌”

自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凭据登录。这就是错误发生的原因。

通常,mac将您的GitHub凭据存储到密钥链访问工具。你以前的git帐户详细信息在那里。所以它与你当前在其他账户中的git回购不匹配。

解决方法简单明了,

进入你的mac的钥匙链访问。 在左边的类别下,你可以找到所有的项目。单击。 右边顶部搜索“git”。 你会得到一些关于Github的项目。 删除所有这些项目。

就这样,给你。

再推一下。它会询问你git的用户名和密码。您的新凭证将再次存储在钥匙链中,您的推送将完成。

华友世纪!

如果你需要更多的帮助,再来找我。

谢谢