您的位置:首页 > 编程语言

解决github不能push的一系列问题

2017-09-14 14:39 106 查看
创建仓库的时候出现的问题当执行:git push -u origin master的时候会出现如下错误:
error: The requested URL returned error: 403 Forbidden while accessing https://legehappy@github.com/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://legehappy@github.com/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://legehappy@github.com/legehappy/cml.git 9ed8700..a86827b master -> master

有时候push的时候会出现下面的问题:
[root@centos-3 cml]# git push
Password:
To https://legehappy@github.com/legehappy/cml.git ! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'https://legehappy@github.com/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://legehappy@github.com/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 git@github.com: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

这样就可以解决以上的问题!!!!!
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  解决 不能 github