无法将新项目推送到github

时间:2019-10-12 10:35:23

标签: git github

我已经在本地创建了一个新项目,并尝试将其按以下方式推送到github:

1. run 'git init' command in myproject directory.
2. run 'git add .'
3. run git commit -m "First commit"
4. Create a repository 'MyRepository' on github site
5. Also added ssh public key at github
6. git remote add origin repository-URL
7. git push -u origin master

步骤7给我一个验证错误:

  

致命:XXX的身份验证失败

我在这里做什么错了?

2 个答案:

答案 0 :(得分:0)

请按照以下步骤操作,这可能会解决您的问题, 1.打开Git Bash并将当前工作目录更改为本地项目。

  1. 将本地目录初始化为Git存储库。 即git init

  2. 将文件添加到新的本地存储库中。这将它们暂存为第一次提交。 即git add。

    1. 提交您在本地存储库中暂存的文件。 即 git commit -m“初始提交”
  3. 复制新创建的仓库的https url 在命令提示符下,添加将在其中推送本地存储库的远程存储库的URL。

即git remote add origin远程存储库URL

然后 git remote -v

  1. 将本地存储库中的更改推送到GitHub。

即git push origin master

答案 1 :(得分:0)

该错误表示您的计算机上没有ssh连接。

您提到您已经创建了ssh-key

  
      
  1. 还在github上添加了ssh公钥
  2.   

您似乎没有使用ssh URL更新远程URL


该怎么办?

  1. 首先,检查是否正确设置了密钥

    ssh-keyscan github.com
    
  2. 如果遇到错误-继续并按照以下详细步骤进行操作。

  3. 如果连接正常,请更新您的本地网址:

    git remote set origin <ssh url>
    

在您的github帐户下创建并添加ssh密钥

来源:https://help.github.com/en/enterprise/2.15/user/articles/adding-a-new-ssh-key-to-your-github-account

生成ssh密钥

  • 打开Git Bash。
  • 运行ssh-keygen并按照屏幕上的消息进行操作(或直接单击 Enter 直至结束)
  • 复制位于以下位置的密钥文件(公共密钥的内容)

     ~/.ssh/id_rsa.pub
    

向Github添加密钥

  • 在任何页面的右上角,单击您的个人资料照片,然后单击“设置”。 enter image description here

  • 在用户设置侧栏中,单击SSH和GPG密钥。
    enter image description here

  • 单击“新建SSH密钥”或“添加SSH密钥”。 enter image description here

  • 将密钥粘贴到“密钥”字段中。 enter image description here

  • 单击“添加SSH密钥”。
    enter image description here

  • 将存储库网址更改为ssh

    git remote set origin <ssh url>