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

我打开终端使git按-f

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

我不确定会有什么问题。


当前回答

确保您拥有正确的访问权限,当分支受到保护时可能会发生这种情况。

我刚刚浪费了四个小时在这上面。

其他回答

增加“个人访问令牌”

自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”。

您必须生成一个新的令牌:这里的步骤是https://docs.github.com/en/github/authenticating-to-github/keeping-your-account-and-data-secure/creating-a-personal-access-token

在本地删除原点的控制

 git remote remove origin

再次添加它,但现在使用您生成的令牌

git remote add origin https: // <token> @ <git_url> .git

然后按一下

git pull https://@<git_url>.git

注意:

什么是git_url?是当前项目示例的url: github.com/yourUser/yourProy

并删除<>字符

在Visual Studio中从Github克隆时,点击Github链接上的“浏览存储库”选项,它将要求登录。

您可能正在尝试推送到私有存储库。在这种情况下,您必须请求管理员验证Collaborator访问。

在我的情况下,我不能克隆github由于用户是错误的。

转到~/.gitconfig 然后尝试删除这行代码(只需删除它,然后保存文件)。

[user]
    name = youruser
    email = youruser@domain.com

或者尝试在CMD或终端中使用一行代码:git config——global——remove-section user

并尝试再次做git克隆。希望它能帮你度过美好的一天。><