git 工具下载地址: https://git-scm.com/downloads
1. 在github上创建一个项目比如: python_learn.
2. 本地创建一个工程目录。名称同git上创建的项目,也为 python_learn
cd python_learn
git init
git config --global user.name "awesomeQ"
git config --global use.email "xueshuxuede1@yeah.net"
创建秘钥:
ssh-keygen -t rsa -C "xueshuxuede1@yeah.net"。一路默认配置就ok
默认秘钥生成的位置是: ~/.ssh/。
登录github后访问: https://github.com/settings/keys。添加组 ssh key。 title 与工程名相同
key的内容为: ~/.ssh/id_rsa.pub的内容。
3. 本地创建目录并提交
cd python_learn
关联github仓库
git remote add origin git@github.com:arsArtD/python_learn.git
git pull origin master
scrapy startproject jobCrawler
cd jobCrawler
scrapy genspider Boss zhipin.com
cd ../
git add .
git status
下面这步是为了设置使其使用步骤2创建的ssh,免得还需要输入username 和 password
git remote set-url origin git@github.com:arsArtD/python_learn.git
git commit . -m 'init commit'
git push origin master
访问github,查看python_learn目录下是否有jobCrawler目录,如果有,则说明创建工程成功。
遇到的问题:
1. 新增的文件夹无法通过git status查看到。原因:需要在文件夹下创建文件才会识别。
2. 已经添加了ssh信息。但是git push的时候还需要输入用户名密码:
git remote set-url origin git@github.com:arsArtD/python_learn.git
3.如果自己有多台电脑需要访问同一个代码库。又不想多台电脑使用同一个ssh信息
解决方法: 在不同的电脑中各自生成ssh 公钥,并将公钥添加到github中的key中。
参考:
https://stackoverflow.com/questions/6565357/git-push-requires-username-and-password
https://www.yiibai.com/git/git_push_operation.html
http://www.cnblogs.com/specter45/p/github.html