解決github不能push的一系列問題

創建倉庫的時候出現的問題當執行:git push -u origin master的時候會出現如下錯誤:

error: The requested URL returned error: 403 Forbidden while accessing https://[email protected]/legehappy/cml.git/info/refs


fatal: HTTP request failed


在config文件中加上你自己的用戶名:

[root@centos-3 cml]# ll -a

總用量 20

drwxr-xr-x 3 root root 4096 9月  13 20:26 .

drwxr-xr-x 3 root root 4096 9月  13 20:25 ..

-rw-r--r-- 1 root root    8 9月  13 20:26 cml.txt

drwxr-xr-x 8 root root 4096 9月  13 20:50 .git

-rw-r--r-- 1 root root    6 9月  13 20:25 README.md

[root@centos-3 cml]# cd .git/

[root@centos-3 .git]# cat config 

[core]

repositoryformatversion = 0

filemode = true

bare = false

logallrefupdates = true

[remote "origin"]

fetch = +refs/heads/*:refs/remotes/origin/*

url = https://[email protected]/legehappy/cml.git

[branch "master"]

remote = origin

merge = refs/heads/master


但是還是會出現這樣的錯誤:

[root@centos-3 cml]# git push


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




解決方法:運行下面的命令,然後再試一次


[root@centos-3 cml]# unset SSH_ASKPASS


已經成功上傳文件了:

[root@centos-3 cml]# git push

Password: 

Counting objects: 5, done.

Compressing objects: 100% (2/2), done.

Writing objects: 100% (3/3), 280 bytes, done.

Total 3 (delta 0), reused 0 (delta 0)

To https://[email protected]/legehappy/cml.git

   9ed8700..a86827b  master -> master





有時候push的時候會出現下面的問題:

[root@centos-3 cml]# git push

Password: 

To https://[email protected]/legehappy/cml.git

 ! [rejected]        master -> master (non-fast-forward)

error: failed to push some refs to 'https://[email protected]/legehappy/cml.git'

To prevent you from losing history, non-fast-forward updates were rejected

Merge the remote changes before pushing again.  See the 'Note about

fast-forwards' section of 'git push --help' for details.


執行強制push就可以上傳代碼(實現穿越):

[root@centos-3 cml]# git push -u origin master -f

Password: 

Total 0 (delta 0), reused 0 (delta 0)

To https://[email protected]/legehappy/cml.git

 + c357d71...9ed8700 master -> master (forced update)

Branch master set up to track remote branch master from origin.


出現的問題:即使在github上面上傳私鑰後push的時候還是需要密碼

[root@centos-3 cml]# git push

Password: 


解決:重置known_hosts和公鑰私鑰

[root@centos-3 .ssh]# echo "" > known_hosts 

[root@centos-3 .ssh]# cat known_hosts 


[root@centos-3 .ssh]# rm -rf id_rsa.pub 

You have new mail in /var/spool/mail/root

[root@centos-3 .ssh]# rm -rf id_rsa 

[root@centos-3 .ssh]# ssh-keygen 

Generating public/private rsa key pair.

Enter file in which to save the key (/root/.ssh/id_rsa): 

Enter passphrase (empty for no passphrase): 

Enter same passphrase again: 

Your identification has been saved in /root/.ssh/id_rsa.

Your public key has been saved in /root/.ssh/id_rsa.pub.

The key fingerprint is:

55:34:5a:c3:20:6d:10:8e:e5:e4:6b:9b:f2:bc:84:4b root@centos-3

The key's randomart image is:

+--[ RSA 2048]----+

|        *+.+*    |

|       B .o+.o   |

|      . +.o      |

|         o       |

|        S        |

|       o o       |

|      E +        |

|     . *         |

|      . +.       |

+-----------------+

[root@centos-3 .ssh]# ls

authorized_keys  id_rsa  id_rsa.pub  known_hosts

[root@centos-3 .ssh]# cat id_rsa.pub 

ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAp8E0HdYbnJI09LchyjfZxQhAv0fYxPh/nvZ/GQiA8/lRzyjlwD3fuobBRKovUxE/XycyM0jOMJGccBAxR4C0mRFBuwkE2DsKIySkQ1eFR3eK+gROA4QpqfS/palqbvSq2odqEOEMv9szRp51Lvb3N9rosVUFmfeyqp0mYQlKwo9i1BNDTqtue2DClLj9zZSiEWvOF3LxtApPUSh6EMrKA1OwqnpKkuXFIvA+6kxE6pYULxp8UHioX/KvOHLe5LyzVq0eNM/cqgsz6UcdQxcYlhY8ovC90NvZYHVbyR9y9XbuuYKUMJqg6A76rCZpnDgMiLZSL7DTZ79suo6zrx7sRw== root@centos-3


然後把祕鑰重新上傳github:

[root@centos-3 cml]# git clone [email protected]:legehappy/cml.git

Initialized empty Git repository in /cml/cml/.git/

The authenticity of host 'github.com (192.30.255.113)' can't be established.

RSA key fingerprint is 16:27:ac:a5:76:28:2d:36:63:1b:56:4d:eb:df:a6:48.

Are you sure you want to continue connecting (yes/no)? yes

Warning: Permanently added 'github.com,192.30.255.113' (RSA) to the list of known hosts.

remote: Counting objects: 9, done.

remote: Compressing objects: 100% (5/5), done.

remote: Total 9 (delta 0), reused 9 (delta 0), pack-reused 0

Receiving objects: 100% (9/9), done.


[root@centos-3 cml]# git push 

Everything up-to-date


這樣就可以解決以上的問題!!!!!


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章