1、先在github网页上创建一个库,右上角点击“create a new repository”相关的键,
进入页面后会有让你填写相关的信息,其中的repository name就是你以后的包名。
“Initialize this repository with a README”这一行勾选上,会省去一步
操作,下面会讲。
2、下载github的客户端,地址http://windows.github.com/
3、安装完github会在桌面出现两个快捷键:GitHub和Git Shell,进入Git Shell
4、这一步要把第一步创建的库clone到本地,操作如下:
ssh -T git@github.com(初始化版本之前先确认认证的公钥是否能用)
正确地结果如下:
warning不用理会。Warning: Permanently added 'github.com,207.97.227.239' (RSA) to the list of known hosts. Hi findingsea! You've successfully authenticated, but GitHub does not provide shell access.
接着执行:
git clone https://github.com/你在github的用户名/第一步创建的库名.git(比如我的是https://github.com/updata7/protobuf_socket.git)
clone成功如下:
5、这样,在github下多了一个目录,就是你在第一步创建的库名,用ls可看,进入这个目录,cd 库名Cloning into 'myRepoForBlog'... Warning: Permanently added 'github.com,207.97.227.239' (RSA) to the list of known hosts. remote: Counting objects: 3, done. remote: Total 3 (delta 0), reused 0 (delta 0) Receiving objects: 100% (3/3), done.
6、初始化git
执行 git init
7、这一步如果在操作第一步时,有勾选“Initialize this repository with a README",可以忽略这一步。
否则,执行下面命令
touch README.md git add README.md git commit -m 'first_commit' git remote add origin https://github.com/你在github的用户名/第一步创建的库名.git git push origin master
8、push(上传)文件,先把你要上传的文件全部拷贝到该目录下,再执行下面命令:git add . git commit -m 'first_commit' git remote add origin https://github.com/你在github的用户名/第一步创建的库名.git git push origin master //上传文件
9、如果都没问题,就可以上github页面刷新,看看你已经上传的文件了。
第8步可能会遇到的问题:
如果执行git remote add origin https://github.com/你在github的用户名/第一步创建的库名.git ,出现错误:
fatal: remote origin already exists则执行以下语句:
如果还出现如下错误:git remote rm originerror: Could not remove config section 'remote.origin'
则需要在你的github安装目录下,找到gitconfig文件,删除
remote "origin"这一行。安装目录可以右键你桌面的Git Shell
查看。
否则
再执行git remote add origin https://github.com/你在github的用户名/第一步创建的库名.git 即可。在执行git push origin master时,报错:
error:failed to push som refs to.......
则执行以下语句:
git pull origin master先把远程服务器github上面的文件先拉来,再push 上去。
饮水思源:
http://www.cnblogs.com/findingsea/archive/2012/08/27/2654549.html
http://blog.csdn.net/dengjianqiang2011/article/details/9260435