今天遇到一个问题.代码在本地服务器,分公司的无法同步代码,后来申请了一个github账号,自己先研究一下,主要是领导决策用不用,你懂得.闲话不说.
首先下载git.exe,反正是测试,一路狂奔next就可以了.
一:初始的时候我在本地创建了一个本地身份证(yourname自定义的名字最好跟自己github的名字一样)
git config --global user.name yourname
git config --global user.emailyourname@yourname.com
二:我实在window下创建的本地身份证,所以自己在任意盘中创建一个git仓库的目录
可以切换到任意盘 命令 cd,
我创建到了F,所以cd /F;创建一层文件夹为了好分辨啊呵呵mkdir gitproject;
三:初始化git仓库
git init (在目录中有初选.git的后缀文件)
四:现在开始管理自己的git仓库
把文件或者项目放在改目录下,如果是单文件的话直接git add sss.file(sss.file文件名)
如果是整个项目下git add . 把内容全部添加到git仓库中;
执行 git commit -m "注释内容" ;
本地仓库建设完了,怎么关联到到自己github账号呢?
1.我们需要在https://github.com/里面注册自己的账号。
2.在git里生成公钥文件,连接github时所需
命令如下:ssh-keygen -t rsa -C "your_email@youremail.com"
3.命令生成后,可以在C:\Users\Administrator\.ssh文件夹下,找到公钥文件,(我的是在Administrator下,你的不一定啊) ,直接enter就可以了,生成的文件如下:
4.打开id_rsa.pub里面的内容,复制到github的ssh keys里面 ,便于通过ssh验证通信。
进入github账号setting中,添加key如图:
直接copy进去就可以.
5.成功之后,我们就可以在git终端上,测试连接后,如果一切没问题的话,连接可以通讯,执行命令如下:
输入ssh –t git@github.com , 出现Hi XXX! You've successfully authenticated, but GitHub does not provide shell access. 表示链接成功。
6.开始上传我们的数据 ,
第一次上传数据需要添加一个远程库
git remote add origin git@github.com:name/repository.git 。
其中名字是本人github账户的名字,repository是建的仓库名字,
如果github的账户名字为guoyingjie ,
建的repository名字为test
则上面的指令为git remote add origin git@github.com:guoyingjie/test.git。
远程库的名字为origin
如果不想用这个名字可以git remote add hhh git@github.com:guoyingjie/est.git
此时远程库名字为hhh
7、第一次上传数据 git push -u origin master,
以后上传数据 git remote origin master。
其中origin是自己在5中定义的远程库名字,
如果名字为hhh git remote hhh master;
遇到这样的错误:
$ git push -u origin master
To git@github.com:yangchao0718/cocos2d.git
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'git@github.com:yangchao0718/cocos2d.git
hint: Updates were rejected because the tip of your current branch is behin
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
请看大神解答:http://jingyan.baidu.com/article/f3e34a12a25bc8f5ea65354a.html
好了呵呵