码迷,mamicode.com
首页 > 其他好文 > 详细

github使用心得

时间:2015-04-24 22:41:10      阅读:203      评论:0      收藏:0      [点我收藏+]

标签:

 目前GitHub非常的火,无论是国内的还是国外的现在都在使用。抽空研究了一下这个东西的使用方法,并总结出来,虽然有一点晚,但是我觉得还是有需要了解和学习的地方。好了,进入主题,一步一步的去介绍,当然最容易的学习方法,当然是跟着github网站提供的步骤去学习。这里我也是针对这个内容来进行总结。

1、github的网址: 技术分享https://github.com  
2、选择login,输入用户名,密码,登陆。登陆之后,就会进入到主页,这里包含了四个基本的应用:
Set Up Git   Create A RepositoryFork a RepositoryBe Social3、Set Up a git (主要目的就是在本地系统上安装好git工具,因为github其实是服务于git的网站)
1、配置用户名和邮箱。 git config --global user.name "Your Name Here"# Sets the default name for git to use when you commitgit config --global user.email "your_email@youremail.com"# Sets the default email for git to use when you commit2、补充说明         git的版本查询    git --version git的路径查询    which git4、Create a Repository
在网页中查收到 Create repository的网页绿色按钮后,输入必要的项目名称后,点击,即可完成创建repository的过程。需要记住的是项目名称为hello.git         创建成功后,就涉及如何在本地创建一个客户端的库,以保证与服务断的同步。客户端的库的创建过程如下:mkdir ~/Hello-World# Creates a directory for your project called "Hello-World" in your user directorycd ~/Hello-World# Changes the current working directory to your newly created directorygit init# Sets up the necessary Git files# Initialized empty Git repository in /Users/you/Hello-World/.git/touch README# Creates a file called "README" in your Hello-World directorygit add README# Stages your README file, adding it to the list of files to be committedgit commit -m ‘first commit‘# Commits your files, adding the message "first commit"git remote add origin 技术分享https://github.com/username/Hello-World.git# Creates a remote named "origin" pointing at your GitHub repogit push origin master# Sends your commits in the "master" branch to GitHub
上述过程当中,涉及到几个比较关键的点,也是我在研究的过程中花了一些时间才弄清楚的地方。下面一一讲解  git init                                     实际上是在一个空目录,或者空项目中,建立一个初步的git扩展。  git add README                 这个意思,是上传README一个文件,当文件比较多的情况下,需要上传目录当中的所有文件,此时应该的写法为 git ad . 记住要有个点。  git commit -m ‘注释说明‘     这个其实就是提交到本地库当中。  git remote add origin 技术分享https://github.com/username/Hello-world.git       他的含义其实是将本地的库 origin,上传到服务器的Hello-world.git当中。  git push -u origin master    意思就是上传,这个地方才是真正的上传
5、Fork a Repo 
fork的理解,其实fork的含义是通知一个git项目的主人,我要将你的代码fork到我的空间去,然后我就可以进行修改了,这样有利于其他未授权的人对代码进行贡献。还有,fork之后,就使用  git clone 技术分享https://github.com/username/Hello-world.git        修改之后,需要提交到github上,此时使用的方法位:git remote add upstream 技术分享https://github.com/octocat/hello-world.git         git fetch ustream  获取未改变的内容。          这里有一个概念,就是 git fetch,和git pull,其实都是从服务器获取代码,相当于update,但是fetch是不自动覆盖,而pull就会自动覆盖掉。此外,还有一个概念,就是当clone之后,origin指向的其实是你自己的repo,而主人的变更是需要通过如下,获得具体的配置跟踪。cd Spoon-Knife# Changes the active directory in the prompt to the newly cloned "Spoon-Knife" directorygit remote add upstream 技术分享https://github.com/octocat/Spoon-Knife.git# Assigns the original repo to a remote called "upstream"git fetch upstream# Pulls in changes not present in your local repository, without modifying your files      我的理解,其实就是分支的问题。所谓分支,其实目的是当你需要同时解决两个问题的时候,而这两个问题为了便于后续在合并,因此会创建一个分支,然后在做meiger,将分支合并,从而解决这样的同时存在的问题。
      因此,当你只提交自己的改变给自己的时候,可以如下:git push origin master# Pushes commits to your remote repo stored on GitHub
   而当你需要与主人的分支进行合并的时候,需要如下做法:git fetch upstream# Fetches any new changes from the original repogit merge upstream/master# Merges any changes fetched into your working files 创建分支的方法:
git branch mybranch# Creates a new branch called "mybranch"git checkout mybranch# Makes "mybranch" the active branch      其实是实现一个branch,然后将这个branch作为当前获得的branch,进行修改。改变当前branch的方法如下:git checkout master# Makes "master" the active branchgit checkout mybranch# Makes "mybranch" the active branch两个branch做最后的合并git checkout master# Makes "master" the active branchgit merge mybranch# Merges the commits from "mybranch" into "master"git branch -d mybranch# Deletes the "mybranch" branch
Pull request 基本含义是,向主人发送请求,通知他,我做了改变,你可以看看。
Unwatch the main repo 的基本含义,是说,对于很多人都进行更新的项目,我做一些选择,放弃一些更新的跟踪。
最后,还想介绍一下删除一个项目的方法,这个方法在github上其实有时候是很难找到的,具体的方法为:
首先,选择项目 -- 然后选择Setting -- Delete this repository

github使用心得

标签:

原文地址:http://www.cnblogs.com/zcc521/p/4454526.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!