git push 403

1. 在github上新建一个空项目。

2. git clone 到本地仓库。

3. git add [一些文件]。

4. git commit -m "first commit"。

5. git remote add origin https://github.com/your name/your project.git。

6. git push -u origin master。报错如下:

error: The requested URL returned error: 403 Forbidden while accessing https://github.com/xxx/xxx.git/info/refs

fatal: HTTP request failed

7. 解决办法:

1. vim .git/config (编辑这个项目仓库目录下的config文件)。
2. 找到[remote "origin"]域。
3. 把url = https://xxx@github.com...
修改为
url = ssh://git@github.com... 4. 保存并退出。

8. 执行git push -u origin master,成功。

 PS:知其然,但是我并不知其所以然。

 纯推测:

 ① 开始用https提交的方式没有通过服务器身份验证。

 ② 改为ssh提交的方式通过了服务器的身份验证(因为我本机生成了ssh key并在github登记过)。

 如果这个推测有问题,还望有高手指正,谢谢。

原文地址:https://www.cnblogs.com/yoyotl/p/5229885.html