《GitHub详细教程》

来源:互联网 发布:产品宣传片制作软件 编辑:程序博客网 时间:2024/05/20 05:31
《GitHub详细教程》 [http://blog.csdn.net/tangbin330/article/details/9128765

该博客主要是讲解Git仓库的操作方法和原理,不涉及GitHub。 


GitHub的独特卖点在于从另外一个项目进行分支的简易性。为一个项目贡献代码非常简单:首先点击项目站点的“fork”的按钮,然后将代码检出并将修改加入到刚才分出的代码库中,最后通过内建的“pull request”机制向项目负责人申请代码合并。已经有人将GitHub称为代码玩家的MySpace。 


在GitHub进行分支就像在Myspace(或Facebook…)进行交友一样,在社会关系图的节点中不断的连线。【熟练掌握分支的概念】 

自己创建仓库:lisuxuan1993/LearningGitHub 

用户名:lisuxuan1993。密码:l0。 

操作指令如下: 

git init 

git add README.md 

git commit -m "first commit" 

git remote add origin https://github.com/lisuxuan1993/LearningGitHub.git 

git push -u origin master 





1.在github上创建一个新的版本库 


github首页,找到下图界面,点击“new repository”按钮: 

file:///C:/Users/Youzh/AppData/Local/Temp/msohtmlclip1/01/clip_image001.png 

填下项目名称、描述、url等信息,然后提交。 

file:///C:/Users/Youzh/AppData/Local/Temp/msohtmlclip1/01/clip_image002.png 

图中标红的一项的意思是只有付费用户才有私有库托管服务,在github上开源(public)项目托管是免费的。 

这样一个新的版本库就创建完毕了。 

接下来我们需要本地版本库和远程版本库(github上的)进行通信,还需要一些配置。 

2.ssh配置 


想要让本地版本库与远程版本库通信,需要配置下SSHkey。 

2.1检查计算机上是否已经有SSH key 

1. $ cd ~/.ssh 

如果出现““No such file ordirectory”或类似的语句,说明缺少ssh的key。 

2.2创建个新的SSH key 

1. $ ssh-keygen -t rsa -C "your_email@youremail.com

比如明河机子上的 

1. $ ssh-keygen -t rsa -C "minghe36@126.com

会出现类似下图的提示: 

file:///C:/Users/Youzh/AppData/Local/Temp/msohtmlclip1/01/clip_image003.png 

直接按下“enter”键即可,然后输入密码。 

file:///C:/Users/Youzh/AppData/Local/Temp/msohtmlclip1/01/clip_image004.png 

一切顺利的话,你可以查看下c:\Users\Administrator\.ssh\id_rsa.pub文件,复制里面的key码。 

2.3增加ssh key到github上 

file:///C:/Users/Youzh/AppData/Local/Temp/msohtmlclip1/01/clip_image005.png 

file:///C:/Users/Youzh/AppData/Local/Temp/msohtmlclip1/01/clip_image006.png 

留意并不需要填写title,github会自动生成,直接把复制的key黏贴到key输入框确定即可。 

2.4配置下git的用户名和email 

1. $ git config --global user.name "minghe" 

2. $ git config --global user.email "minghe36@126.com

配置结束。 

3.本地版本库和远程版本库的通信 


3.1克隆个远程版本库 

file:///C:/Users/Youzh/AppData/Local/Temp/msohtmlclip1/01/clip_image007.png 

“cdd:\git-test”切换到该目录。 

3.2推送更新到远程版本库 

先随意提交个文件到版本库 

file:///C:/Users/Youzh/AppData/Local/Temp/msohtmlclip1/01/clip_image008.png 

由于是克隆远程版本库,已经存在远程分支origin,无需再创建。 

(PS:创建远程分支:git remote addorigin git@github.com:minghe/git-test.git) 

查看远程分支情况,可以使用git branch -r命令。 

推送修改到远程版本库: 

file:///C:/Users/Youzh/AppData/Local/Temp/msohtmlclip1/01/clip_image009.png 

git push命名将推送内容到远程服务器。 

与之相反的命令就是git pull。 

git 提交修改到github上 

1,在GITHUB.com注册相应帐号,建立Repositories。 

file:///C:/Users/Youzh/AppData/Local/Temp/msohtmlclip1/01/clip_image010.png 

3,克隆GitHub项目 

git clone git://github.com/xxx/xxx.git 

注:要转到file:///C:/Users/Youzh/AppData/Local/Temp/msohtmlclip1/01/clip_image011.png在进行git bash操作 

4,分支的创建和合并 

# git branch local 

# git checkout local 切换到local 

注:这里的分支是在本地,没有在github服务器上建立分支。 

5, 在local分支进行开发,开发完成后与master分支合并 

# git checkout master 

# git merge local 

# git branch -d local 合并完后删除local 

6, 

file:///C:/Users/Youzh/AppData/Local/Temp/msohtmlclip1/01/clip_image013.png 

7, 

file:///C:/Users/Youzh/AppData/Local/Temp/msohtmlclip1/01/clip_image015.png 

注:这时github还没有我添加的文件如: 

file:///C:/Users/Youzh/AppData/Local/Temp/msohtmlclip1/01/clip_image017.png 

file:///C:/Users/Youzh/AppData/Local/Temp/msohtmlclip1/01/clip_image018.png 

8,用$ git pull 获取现在master的最新更改。因为我对README.md 做了修改。 

file:///C:/Users/Youzh/AppData/Local/Temp/msohtmlclip1/01/clip_image019.png 

9,最后将修改的内容提交到github服务器上。 

$ git push origin master 

注:一般origin默认为你clone的Repositories如: [url=mailto:%E2%80%9Dgit@github.com:xxx/new-project.git]”git@github.com:xxx/new-project.git[/url]” 也可以自 

定义远程服务器别名origin 

# git remote add origin git@github.com:xxx/new-project.git 

最后成功。 

file:///C:/Users/Youzh/AppData/Local/Temp/msohtmlclip1/01/clip_image021.png 



《Spring软件的GitHub地址》 

——The Spring Framework repository has moved to http://github.com/SpringSource/spring-framework. 

See the readme there for details on working with Git, building the framework, etc. 

ote that svn-based access is still available via GitHub's support for Subversion clients, e.g.: 



$ svn checkout https://github.com/SpringSource/spring-framework 


See https://github.com/blog/966-improved-subversion-client-support for more details. 


——http://projects.spring.io/spring-framework 

《git - 简明指南》 


[http://rogerdudler.github.io/git-guide/index.zh.html


《给SVN泼盆冷水,是时候用GIT了》 


[http://www.jianshu.com/p/fa7eac6bb2b2


作者:Terry_Wang。简介:我只是不想虚度光阴。充实和富有挑战,才是自己骨子里最本质的东西。我不 

期望自己能改变别人的世界,但愿能改变自己的世界。日期:2013-12-31 。 


没有要排除任何工具的意思,只是眼下最流行的“版本管理系统”非GIT莫属。 


Git有什么不一样: 

——SVN属于中心式的仓库管理,统一维护在Server端,而Git属于分布式的仓库管理,每个开发者都拥有自 

己的本地仓库,并且每个仓库都是平等的。 

——由于你自己本身就拥有仓库,那么Git在本地磁盘上就保存着所有有关当前项目的历史更新,并且Git中 

的绝大多数操作都只需要访问本地文件和资源,不用连网,所以处理起来速度飞快。用SVN的话,没有网络 

或者断开VPN你就无法做任何事情。但用Git的话,就算你在飞机或者火车上,都可以非常愉快地频繁提交 

更新,等到了有网络的时候再上传到远程的镜像仓库。换作其他版本控制系统,这么做几乎不可能,抑或是 

非常麻烦。 

——并且Git中每个克隆(clone)的版本库都是平等的。你可以从任何一个版本库的克隆来创建属于你自己的 

版本库,同时你的版本库也可以作为源提供给他人,只要你愿意。 

——Svn?Svn是统一管理的好吧。开发时你的Boss说了算,说什么时候提交代码就什么时候提交代码,说 

什么时候更新就统一更新,你觉得很爽? 

——Git?Git的提交不会被打断,直到你的工作完全满意了,PUSH给他人或者他人PULL你的版本库,合并 

会发生在PULL和PUSH过程中,不能自动解决的冲突会提示您手工完成。 

——开源社区(比如OSC@China)都采用了Git,而不是SVN。 



Git for windows 和 msysGit: 

这个你大致了解下就行,只是多一种选择,多一条路。msysGit的主页提供了两个项目:Git for Windows和msysGit,并写明了它们的详细区别。 

个人认为,Git for Windows适合绝大多数程序猿(又见绝大多数),所以,强烈建议安装Git for Window。 

msysGit使用一种很BT也很NB的方式来安装。先安装一个最小的MinGW/MSYS系统,然后使用git pull 所有的源码,调用gcc在本地编译成可执行文件。 
0 0
原创粉丝点击