git push -u origin master 出错 \Permission denied (publickey). fatal: Could not read from remote repo

在本地写好项目,一路git add * 和 git commit -m 'XXX'

然后在github上新建仓库,准备关联后,把代码推送至远程仓库

在git push 时就出错了:

(venv) [willie@localhost DJangoHotel_Python]$ git remote add origin git@github.com:williezh/hotelbooksystem.git
(venv) [willie@localhost DJangoHotel_Python]$ git remote -v

origin git@github.com:williezh/hotelbooksystem.git (fetch)

origin git@github.com:williezh/hotelbooksystem.git (push)

(venv) [willie@localhost DJangoHotel_Python]$ git push -u origin master

\Permission denied (publickey).
fatal: Could not read from remote repository.


Please make sure you have the correct access rights

and the repository exists.

查看了好多博客,并试验后,发现是密钥配置的问题:

参考:http://blog.csdn.net/hhhccckkk/article/details/50737077


解决了Permission的问题后,又出现了hint的问题

(venv) [willie@localhost DJangoHotel_Python]$ git push -u origin master
To github.com:williezh/hotelbooksystem.git
 ! [rejected]        master -> master (fetch first)
error: failed to push some refs to 'git@github.com:williezh/hotelbooksystem.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

(venv) [willie@localhost DJangoHotel_Python]$ git pull
warning: no common commits
remote: Counting objects: 5, done.
remote: Compressing objects: 100% (5/5), done.
remote: Total 5 (delta 0), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (5/5), done.
From github.com:williezh/hotelbooksystem
 * [new branch]      master     -> origin/master
Auto packing the repository in background for optimum performance.
See "git help gc" for manual housekeeping.
There is no tracking information for the current branch.
Please specify which branch you want to merge with.
See git-pull(1) for details.


    git pull <remote> <branch>


If you wish to set tracking information for this branch you can do so with:


    git branch --set-upstream-to=origin/<branch> master

(venv) [willie@localhost DJangoHotel_Python]$ git pull origin master
From github.com:williezh/hotelbooksystem
 * branch            master     -> FETCH_HEAD
fatal: refusing to merge unrelated histories

解决方法参考:http://blog.csdn.net/byoooy/article/details/52263404

(venv) [willie@localhost DJangoHotel_Python]$ git pull origin master --allow-unrelated-histories
From github.com:williezh/hotelbooksystem
 * branch            master     -> FETCH_HEAD
error: The following untracked working tree files would be overwritten by merge:
.gitignore
Please move or remove them before you merge.
Aborting

(venv) [willie@localhost DJangoHotel_Python]$ rm -f .gitignore
(venv) [willie@localhost DJangoHotel_Python]$ git pull origin master --allow-unrelated-histories

From github.com:williezh/hotelbooksystem
 * branch            master     -> FETCH_HEAD
Auto-merging README.md
CONFLICT (add/add): Merge conflict in README.md
Automatic merge failed; fix conflicts and then commit the result.

(venv) [willie@localhost DJangoHotel_Python]$ cat README.md
(venv) [willie@localhost DJangoHotel_Python]$ vim README.md
(venv) [willie@localhost DJangoHotel_Python]$ git add *
(venv) [willie@localhost DJangoHotel_Python]$ git commit -m 'fix the readme.md'
(venv) [willie@localhost DJangoHotel_Python]$ git push -u origin master

可以上传了,但是因为包含了虚拟环境的文件夹venv,导致文件太大,上传很慢

果断ctrl+c打断上传,然后:

(venv) [willie@localhost DJangoHotel_Python]$ deactivate
 [willie@localhost DJangoHotel_Python]$ cd ..
[willie@localhost projects]$ git clone https://github.com/williezh/hotelbooksystem
[willie@localhost projects]$ cd hotelbooksystem/

把DJangoHotel_Python文件夹里,除venv外的所有可见文件及文件夹,复制到当前目录(手动操作)

[willie@localhost hotelbooksystem]$ git add *
[willie@localhost hotelbooksystem]$ git commit -m 'version 1.0'
[willie@localhost hotelbooksystem]$ git push -u origin master

输入用户名和密码,成功上传!


总结:本地仓库,在git init之后,就应该编辑.git/info/exclude文件,忽略掉虚拟环境和~文件,以免git push的时候文件太大。

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值