1.首先下载git,下载地址https://git-scm.com/downloads选择自己电脑的对应版本
2.下载安装:一直next即可
安装好后在桌面右键你会发现有个Git Bash here,这个就是git的命令界面
3.博主用的是window系统故以window为例(如果用的mac和linux的,请见谅)
4.开始配置本地仓库
第一步:创建一个身份标识(很重要)
git config --global user.name xxx(改为你的用户名)
git config --global user.email XXX(改为你的邮箱名)
第二步:cd到你喜欢的盘
cd /e
第三步:建立本地git仓库
mkdir GitDemo
cd GitDemo
第四步:创建一个存放你准备上传项目的文件夹
mkdir Demo1
cd Demo1
第五步:将你的项目拷贝到此文件夹(这里我用text.html文件代替)
比如我创建一个demo.html的网页在里面
第六步:初始此文件夹(此时里面会多一个.git的文件夹,此时这个文件夹就相当于本地仓库的具体存在)
git init
第七步:添加项目到本地仓库
git add demo.html
或另一个命令
git add .(注意后面有个点)
然后再输入(引号里填的是你这次操作的注释可以换)
git commit -m "测试项目"
至此本地仓库里已经准备好了你要上传的内容
接下来说明如何将本地仓库的项目上传到github上
第一步:现在github官网上注册一个账号密码 https://github.com
第二步:创建远程仓库
点击绿色图标旁边的下拉菜单
然后选择New repository
填上仓库名字、仓库描述,然后确定即可
第三步:在本地创建ssh密钥
ssh-keygen -t rsa -C "your_email@youremail.com"
将emali改成自己的
命令生成后,可以在C:\Users\xxx\.ssh文件夹下,找到公钥文件,
然后我们需要新建一个无后缀名的config文件,把里面加入如下内容,为了防止连接github失败。
Host github.com
User git
Hostname ssh.github.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa
Port 443
然后拷贝,id_rsa.pub里面的内容,复制到github的ssh keys里面 ,便于通过ssh验证通信。
第四步:申请ssh密钥
点击Setting
点击SSH and GPG keys选项
然后申请密钥
第五步:成功之后,我们就可以在git终端上,测试连接后,如果一切没问题的话,连接可以通讯,执行命令如下:
ssh –t git@github.com
出现这个结果PTY allocation request failed on channel 0即成功了
第六步:现在开始将本地仓库的内容上传到github
$ git remote add origin git@github.com:maozuowei/mao.git
这时候如果出现fatal: remote origin already exists.错误可参考http://blog.csdn.net/top_code/article/details/50381432
那么就先执行git remote rm origin命令删除远程已经存在的仓库
然后再执行$ git remote add origin git@github.com:maozuowei/mao.git命令即可
红色的那串地址在这里可以找到:
第七步:开始上传
执行$ git push -u origin master
这时如果出现错误
error: failed to push some refs to 'git@github.com:maozuowei/mao.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.
意思是远程仓库里存在本地没有的文件(一般是你自己在github网站上新建了read.me文件),所以先git pull下来(pull之后你的本地就会出现这个文件),再git push就可以啦。
先执行$ git pull --rebase origin master
然后执行$ git push -u origin master
大功告成!!!
如果有问题没有涉及到可以在下面留言,也希望各位博友对我的文章指正,谢谢。
- 1
- 1