不得不说,github的项目文件上传方面需要整的东西挺多的,可能是因为考虑的安全性因素比较多,所以才会很麻烦. 之前看过两次视频,没看太懂,前几天自己没事儿瞎弄,给整好了,写出来分享一下,也防止以后自己忘了到底是怎么弄出来的..
具体的方法:
1.首先,注册之类的问题 就不多说了,注册完了,在官网 http://www.github.com 进行下载window系统下的客户端.
2.登陆进入github 在右侧的位置
在右侧的位置, new一个项目目录出来,
进行设置项目的 标题和描述信息 ,下面的那个 Initialize this ...README勾选上,不然在后面会带来不必要的麻烦 .现在远程的仓库就已经创建完成,就是你的远程仓库的 地址信息
3.接下来,在客户端进行操作, 在客户端的github中, 新添加一个本地的项目,用做后期的与远程仓库同步的操作,注意,项目的本地位置,就放在你的本地的项目的位置就可以了.不再需要为其创建一个新的目录.
4.在创建完成后. 在github的客户端, 会显示已经做出了修改, 进行上传,但是注意,这个时候的上传时存储在一个临时的区域,还没有和远程的仓库进行关联!
5.接下来才是重点! 也是上传的关键! 在客户端的github中 open in git shell
生成ssh文件: 公共钥匙:
ssh-keygen -t rsa -C "your_email@youremail.com"
命令生成后,在 C:\Users\Administrator\.ssh 位置,我们可以看到这个
6.在github的网页上 ,个人中心的settings配置部分,进行添加ssh key ,title无所谓
7.然后回到git bash来,输入如下命令检测是否能够ssh连接github,
ssh -T git@github.com
可能会出现警告,不要管他,输入的密码是你建立密钥时候的密码。
8.先将网上的代码复制到本地
git clone https://github.com/logobitch/MyBlog.git
后面填写自己的git账户 和项目的名称即可之后我们按照如下命令将本地仓库递交到远程仓库:
上传之前要对修改做一次总结,写好“日志”
git commit -m ".................."
9.将本地仓库和远程仓库建立连接: 其中后面的部分是你在网页上的github项目中拿到的项目地址,
git remote add origin git@github.com:logobitch/origin.git
10.完成上传
git push -u origin master
总结一下出现的问题:
如果执行git remote add origin
https://github.com/Flowerowl/stumansys.git
,出现错误:
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 上去。
还有: error: failed to push some refs to 'https://github.com/logobitch/MyBlog.git'
用git push代码到远程仓库的时候出现错误
error:failed to push some refs to ...
Dealing with “non-fast-forward” errors
From time to time you may encounter this error while pushing:
$ git push origin master
To ../remote/
! [rejected] master -> master (non-fast forward)
error: failed to push some refs to '../remote/'
To prevent you from losing history, non-fast-forward updates were rejected
Merge the remote changes before pushing again. See the 'non-fast forward'
section of 'git push --help' for details.
2. 先把git的东西fetch到你本地然后merge后再push
$ git fetch
$ git merge
这2句命令等价于
$ git pull