Skip to content

Instantly share code, notes, and snippets.

@rwx------
Last active December 13, 2016 08:49
Show Gist options
  • Save rwx------/fe9267430d327c09b6a11b72148e7161 to your computer and use it in GitHub Desktop.
Save rwx------/fe9267430d327c09b6a11b72148e7161 to your computer and use it in GitHub Desktop.

环境介绍

在整个贡献代码过程中,应该牢记以下几个环境。其实绝大部分的操作都是在我们的本地电脑完成。  

- 别人的github项目A: https://github.com/rwx------/zabbix-templates  
- 我的github账号B:   https://github.com/RickieL  
- 我的本地电脑C:      local  

后面的介绍中,每个步骤的操作环境都会以[A]、[B]、[C]来标示。

步骤介绍

  • 1.[B]登录自己的github账号

  • 2.[A]fork别人的代码

    登录后,打开你需要贡献代码的项目,如本例中的 https://github.com/rwx------/zabbix-templates 
    点击页面上面的fork按钮,对项目进行fork
    此时,你自己的账号下,会产生一个新的项目: https://github.com/RickieL/zabbix-templates 
  • 3.[C]克隆项目到本地
     git clone git@github.com:RickieL/zabbix-templates.git
     cd zabbix-templates
  • 4.[C]在本地对代码进行修改和提交
    echo 'new test' >> README.md
    git add README.md
    git commit -m "新增测试代码"
  • 5.[C]在本地添加上游(注意不是自己的)远程仓库
    你在努力让项目变得更好的同时,项目原作者也在努力,也有在变更原代码。怎样让上游仓库的更改同步到本地呢?
    git remote add upstream git@github.com:rwx------/zabbix-templates.git
    git fetch upstream # 从上游仓库获取分支及相关的提交信息,它们将被保存在本地upstream/master分支
  • 6.[C]切换到本地的master分支
    git checkout master
  • 7.[C]合并上游的更新
# 把`upstream/master` 分支合并到本地的 `master` 分支,本地的 `master` 分支便跟上游仓库保持同步了,并且没有丢失你本地的修改。
# 操作过程中,可能自己的修改和上游的修改产生了冲突,需要解决冲突的部分。
git merge upstream/master
  • 8.[C]提交到自己的github仓库。
    git push origin master
  • 9.[B]pull request
在自己的github页面,发起pull request请求, 别人接不接受你的pull request,就看你的代码质量和原作者的态度了😂.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment