1、以github为例,首先创建账号;
2、在github上创建一个代码仓库
3、创建项目名称,如下图:
4、创建完之后,需要ssh key
(1) 在终端输入:ssh-keygen -t rsa -C 'your email@domain.com' //输入你的邮箱,其实默认这个也可以。
(2)终端会提示(Enter file in which to save the key (/Users/gobi/.ssh/id_rsa): 这个时候输入保存rsa文件名。
(3)输入的密码不能太短,这个时候我取名字为hello。
(4)取出hello.pub内的公钥密码,快速找到hello.pub文件 control+空格,然后输入hello.pub 找到文件后用xcode打开,内容大概如下:
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDgopsXMenmxzusfjbrPB4RRlvdzTVSEzRh66RYDjvH.......(注意如果后面有邮箱的名字去掉);
(5)、首先在github上面选中settings
(6)、将公钥密码放入到下图的key中,title任意输入即可。
5、将代码上传到github
(1)首先进入项目的目录:cd 项目的路径(/Users/gobi/Downloads/WorkingCalendar)
(2)以下git命令
git init
git commit -m 'stumansys'
git remote add origin https://github.com/aimsgmiss/WorkingCalendar
git push origin master
(3) 以下是参照别人的,可能会进入vim编辑器,退出按esc键。
如果执行git remote add origin
https://github.com/aimsgmiss/WorkingCalendar
如果出现错误:
fatal: remote origin already exists
则执行以下语句:
git remote rm origin
再往后执行git remote add origin https://github.com/Flowerowl/stumansys.git 即可。
在执行git push origin master时,报错:
error:failed to push som refs to.......
则执行以下语句:
git pull origin master
先把远程服务器github上面的文件拉先来,再push 上去。
如果出现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.
可以采取暴力的手段:git push origin master -f
最后大功告成。