在本地写好项目,一路git add * 和 git commit -m 'XXX'
然后在github上新建仓库,准备关联后,把代码推送至远程仓库
在git push 时就出错了:
(venv) [willie@localhost DJangoHotel_Python]$ git remote add origin [email protected]:williezh/hotelbooksystem.git
(venv) [willie@localhost DJangoHotel_Python]$ git remote -v
origin [email protected]:williezh/hotelbooksystem.git (fetch)
origin [email protected]:williezh/hotelbooksystem.git (push)
(venv) [willie@localhost DJangoHotel_Python]$ git push -u origin master
\Permission denied (publickey).
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
(venv) [willie@localhost DJangoHotel_Python]$ git pull
warning: no common commits
(venv) [willie@localhost DJangoHotel_Python]$ git pull origin master
From github.com:williezh/hotelbooksystem
解决方法参考: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
(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的时候文件太大。