“git push”后返回“Error 403”解决方法

问题描述:

1,mac ox系统,terminal上运行命令git push出现403错误;

2,代码是在别人的github(暂且叫origin branch吧)上克隆的,修改和添加了部分代码后欲提交到该“origin branch”,报403错误;

 

发现问题:

1,403error是应为“origin branch”不允许我提交,查了一些网站,有些说是SSH链接导致无法访问对端网站,设置网络http为ssh即可:http://stackoverflow.com/questions/7438313/pushing-to-git-returning-error-code-403-fatal-http-request-failed

2,折腾了半天没弄好重新回来研究git 提交代码的流程,才发现问题;

3,“origin branch”是别人的github,我如果想提交我的代码,不能直接从我本地git提交到远端的“origin branch”。我只能先将我本地git提交到我自己的github,比如“mygithub branch”,然后再从“mygithub branch”提交到“origin branch”。

4,github的代码提交貌似只支持github到github的远端到远端的提交,本地到本地,或本地git到其他帐户的远端github交叉提交是不允许的。

 

解决问题:

1,首先要fork “origin branch”的 project 代码到你自己的 github;

2,然后修改你本地 的配置文件git.config ,修改 url 为你自己的用户名地址(将原来“origin branch” 的地址改为“mygithub branch”的地址,目的是让你本地git提交地址修改为你自己的github地址“mygithub branch”);

3,git push,提交你的本地代码到你的github,比如“mygithub branch”;

4,登录你的github,从web端创建一个pull request到“origin branch”,这样就可以把github的代码pull到“origin branch”代码库;

5,“origin branch”的管理员看到pull请求时,选择merge the change into the project,合并你提交修改的代码到project代码库;

6,完成代码提交。现在你就可以从“origin branch”端看到你提交的代码了,同时你也收到一封简短的邮件:

Merged #1.
Reply to this email directly or view it on GitHub.

 

 

posted @ 2014-04-17 16:18  McQueen1987  阅读(19938)  评论(0编辑  收藏  举报