GitHub学习笔记

安装

Ubuntu上安装Git

sudo apt-get install git

Windows上安装Git

msysgit是Windows版的Git。从http://msysgit.github.io/下载,然后按默认选项安装就可以。安装完毕后,在開始菜单里找到”Git”|”Git Bash”,蹦出一个相似命令行窗体的东西,就说明Git成功安装!

配置

打开命令行。输入例如以下代码:

git config --global user.name "YOUR NAME"
git config --global user.email "YOUR EMAIL ADDRESS"

注意git config命令的--global參数。用了这个參数,表示你这台机器上全部的Git仓库都会使用这个配置,当然也能够对某个仓库指定不同的username和Email地址。

创建仓库

  • 点击GitHub页面右上角的“+”,然后点击“New repository”。
  • 输入仓库的名称及其描写叙述信息。

  • 选择仓库是公开的还是私有的(仅仅同意付费用户创建)。
  • 选择”Initialize this repository with a README.”。
  • 点击”Create repository”。

也可从命令行输入例如以下语句:
mkdir repoName
cd repoName
git init

提交更新

  • 在仓库的文件列表点击”README.md”。
  • 点击编辑button,对文件作出改动,文件内容上方有预览button能够预览改动效果。

  • 在”Commit changges”下方输入简单的有意义的更新信息。
  • 点击”Commit changes”。


    最后一步除了”Commit changes”之外还有” Create a new branch for this commit and start a pull request”选项,能够用此选项创建一个pull request。管理员就可以点击”Merge pull request”合并结果。

    假设从命令行合并。过程例如以下:
    Step 1: From your project repository, bring in the changes and test.
    git fetch origin
    git checkout -b chinaeagle001-patch-1 origin/chinaeagle001-patch-1
    git merge master
    Step 2: Merge the changes and update on GitHub.
    git checkout master
    git merge --no-ff chinaeagle001-patch-1
    git push origin master

Fork A Repo

创建分支的样例

  • On GitHub, navigate to the octocat/Spoon-Knife repository.
  • Fork buttonIn the top-right corner of the page, click Fork.

同步分支

创建分支的本地克隆。

  • 在GitHub页面,导航到你的分支,复制分支的URL。

  • 打开命令行。输入:git clone https://github.com/YOUR-USERNAME/Spoon-Knife
  • 回车,本地克隆创建完毕。

配置Git使分支与原始的仓库同步

  • On GitHub, navigate to the octocat/Spoon-Knife repository.
  • 复制原始仓库的URL。
  • 在命令行输入git remote -v并点击回车。能够看到当前配置的你的分支的远程仓库。


    git remote -v
    origin https://github.com/YOUR_USERNAME/YOUR_FORK.git (fetch)
    origin https://github.com/YOUR_USERNAME/YOUR_FORK.git (push)

  • 输入git remote add upstream。然后粘贴复制的URL并点击回车。
    git remote add upstream https://github.com/octocat/Spoon-Knife.git

  • 此时,再次输入git remote -v,能够看到例如以下信息:
    git remote -v
    # origin https://github.com/YOUR_USERNAME/YOUR_FORK.git (fetch)
    # origin https://github.com/YOUR_USERNAME/YOUR_FORK.git (push)
    # upstream https://github.com/ORIGINAL_OWNER/ORIGINAL_REPOSITORY.git (fetch)
    # upstream https://github.com/ORIGINAL_OWNER/ORIGINAL_REPOSITORY.git (push)

如今,就能够通过少量的Git命令使分支与原始仓库同步。
git fetch upstream
git checkout master
git merge upstream/master

The sky’s the limit with the changes you can make to a fork, including:
- Creating branches: Branches allow you to build new features or test out ideas without putting your main project at risk.
- Opening pull requests: If you are hoping to contribute back to the original repository, you can send a request to the original author to pull your fork into their repository by submitting a pull request.

posted @ 2016-02-18 13:38  mengfanrong  阅读(314)  评论(0编辑  收藏  举报