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

我打开终端使git按-f

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

我不确定会有什么问题。


当前回答

我使用gh命令行工具(顺便说一下,这很神奇)

就我而言,我登录了另一个github账户。我只需要运行:

gh auth logout
gh auth login

然后使用正确的帐户进行身份验证流程。

其他回答

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

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

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

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

然后,

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

从系统中删除所有github.com凭据详细信息。

对于mac

从Keychain Access中删除github.com密码。

对于windows

从凭证管理器中删除凭证。

您必须生成一个新的令牌:这里的步骤是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

并删除<>字符

所以你的url当前看起来如下所示

https://github.com/RevanthM/Log_Monitoring

它应该是这样的

https://RevanthM@github.com/RevanthM/Log_Monitoring

不同的是,在url的开头,我添加了我的github用户名,后面跟着一个@符号。