git推送到github報錯:error: The requested URL returned error: 403 Forbidden while accessing https://github.com

wadeson發表於2017-08-03

最近使用git命令從github克隆倉庫到版本,然後進行提交到github時報錯如下:

[root@node1 git_test]# git push origin master
error: The requested URL returned error: 403 Forbidden while accessing https://github.com/jsonhc/git_test.git/info/refs

fatal: HTTP request failed

解決辦法:參考 http://sharadchhetri.com/2014/08/16/error-requested-url-returned-error-403-forbidden-accessing-github-repo/

這臺本機沒有配置與github的ssh金鑰連線,直接通過的是httpds

1、確保不是git版本d低的問題

[root@wadeson wadeson]# git --version
git version 1.7.1

2、從github克隆倉庫到本地:

git clone https://github.com/jsonhc/git_test.git

[root@wadeson wadeson]# git clone https://github.com/jsonhc/git_test.git
Initialized empty Git repository in /home/wadeson/git_test/.git/
remote: Counting objects: 20, done.
remote: Total 20 (delta 0), reused 0 (delta 0), pack-reused 20
Unpacking objects: 100% (20/20), done.

3、檢視倉庫內容,然後增加需要提交的檔案

[root@wadeson git_test]# ll
總用量 20
-rw-r--r--. 1 root root 712 7月 31 23:59 flask_first.py
-rw-r--r--. 1 root root 2766 7月 31 23:59 landing.py
-rw-r--r--. 1 root root 1881 7月 31 23:59 menu_list.py
-rw-r--r--. 1 root root 10 7月 31 23:59 README.md
-rw-r--r--. 1 root root 377 7月 31 23:59 total.py

[root@wadeson git_test]# mv ../statistics_ip.py ./
[root@wadeson git_test]# ll
總用量 24
-rw-r--r--. 1 root root 712 7月 31 23:59 flask_first.py
-rw-r--r--. 1 root root 2766 7月 31 23:59 landing.py
-rw-r--r--. 1 root root 1881 7月 31 23:59 menu_list.py
-rw-r--r--. 1 root root 10 7月 31 23:59 README.md
-rw-r--r--. 1 root root 377 8月 3 15:01 statistics_ip.py

4、git config --global user.name "json_hc"

git config --global user.email "json_hc@163.com"

5、git remote set-url origin https://jsonhc@github.com/jsonhc/git_test.git

這條命令就是修改了.git/config下面的這條:

  url = https://jsonhc@github.com/jsonhc/git_test.git(原始url為url = https://github.com/jsonhc/git_test.git

6、git add statistics_ip.py

git commit -m "add statistics_ip.py to statistics ip of nginx"

[root@wadeson git_test]# git commit -m "add statistics_ip.py to statistics ip of nginx"
[master a460f0f] add statistics_ip.py to statistics ip of nginx
1 files changed, 22 insertions(+), 0 deletions(-)
create mode 100644 statistics_ip.py

7、git push -u origin master     第一次推送加上-u

[root@wadeson git_test]# git push -u origin master
Password:        這裡需要提供github的密碼
Counting objects: 3, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (2/2), 276 bytes, done.
Total 2 (delta 1), reused 0 (delta 0)
remote: Resolving deltas: 100% (1/1), completed with 1 local object.
To https://jsonhc@github.com/jsonhc/git_test.git
8e23043..a460f0f master -> master
Branch master set up to track remote branch master from origin.

然後進入github網站檢視已歲推送的檔案了

 

現在使用另外的主機進行開發的時候,首先第一步:

git pull遠端倉庫的檔案

[root@node1 git_test]# git pull origin master
Password:
remote: Counting objects: 2, done.
remote: Total 2 (delta 1), reused 2 (delta 1), pack-reused 0
Unpacking objects: 100% (2/2), done.
From https://github.com/jsonhc/git_test
* branch master -> FETCH_HEAD
Updating 8e23043..a460f0f
Fast-forward
statistics_ip.py | 22 ++++++++++++++++++++++
1 files changed, 22 insertions(+), 0 deletions(-)
create mode 100644 statistics_ip.py
[root@node1 git_test]# ll
total 24
-rw-r--r-- 1 root root 712 Aug 3 14:41 flask_first.py
-rw-r--r-- 1 root root 2766 Aug 3 14:41 landing.py
-rw-r--r-- 1 root root 1881 Aug 3 14:41 menu_list.py
-rw-r--r-- 1 root root 10 Aug 3 14:41 README.md
-rw-r--r-- 1 root root 377 Aug 3 15:24 statistics_ip.py
-rw-r--r-- 1 root root 377 Aug 3 14:41 total.py

這樣才能保證不衝突,得到的是新的版本

 

下次再次從本地提交就不需要執行以上部分操作:

[root@node1 wadeson]# cd git_test/
[root@node1 git_test]# ll
total 28
-rw-r--r-- 1 root root 712 Aug 3 14:41 flask_first.py
-rw-r--r-- 1 root root 2766 Aug 3 14:41 landing.py
-rw-r--r-- 1 root root 1881 Aug 3 14:41 menu_list.py
-rw-r--r-- 1 root root 10 Aug 3 14:41 README.md
-rw-r--r-- 1 root root 377 Aug 3 15:24 statistics_ip.py
-rw-r--r-- 1 root root 739 Aug 3 15:58 statistics_nginx_ip_flow.py
-rw-r--r-- 1 root root 377 Aug 3 14:41 total.py
[root@node1 git_test]# git add statistics_nginx_ip_flow.py
[root@node1 git_test]# git commit -m "in additional ip and flow of nginx"
[master 6d15afd] in additional ip and flow of nginx
1 files changed, 34 insertions(+), 0 deletions(-)
create mode 100644 statistics_nginx_ip_flow.py
[root@node1 git_test]# git push origin master
Password:
Counting objects: 4, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 637 bytes, done.
Total 3 (delta 1), reused 0 (delta 0)
remote: Resolving deltas: 100% (1/1), completed with 1 local object.
To https://jsonhc@github.com/jsonhc/git_test.git
a460f0f..6d15afd master -> master

 

 

注意:

(gnome-ssh-askpass:24029): Gtk-WARNING **: cannot open display:

幫助
1
unset SSH_ASKPASS

  

 從一個遠端的github只有一個README.md的新專案,將本地資料進行提交的具體步驟:
1、將遠端專案克隆到本地
  git clone https://github.com/jsonhc/tools.git
2、git config --global user.name "json_hc"
 git config --global user.email "json_hc@163.com"
3、修改提交的https的url
  git remote set-url origin https://jsonhc@github.com/jsonhc/tools.git
4、新增需要提交的資料
  git add init.sh
5、進行提交
  git commit -m "init shell script"
6、

[root@xen tools]# git push -u origin master
Password:        輸入密碼

Counting objects: 4, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 653 bytes, done.
Total 3 (delta 0), reused 0 (delta 0)
To https://jsonhc@github.com/jsonhc/tools.git
f431558..59cbb6a master -> master
Branch master set up to track remote branch master from origin.

相關文章