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仓库都会使用这个配置,当然也可以对某个仓库指定不同的用户名和Email地址。

创建仓库

  • 点击GitHub页面右上角的“+”,然后点击“New repository”。
  • 输入仓库的名称及其描述信息。
  • 选择仓库是公开的还是私有的(只允许付费用户创建)。
  • 选择”Initialize this repository with a README.”。
  • 点击”Create repository”。

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

提交更新

  • 在仓库的文件列表点击”README.md”。
  • 点击编辑按钮,对文件作出修改,文件内容上方有预览按钮可以预览修改效果。
  • 在”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.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值