github更新本身Fork的代碼

github上有個功能叫fork,能夠將別人的工程複製到本身帳號下。python

這個功能很方便,但其有一個缺點是:當源項目更新後,你fork的分支並不會一塊兒更新,須要本身手動去更新。git

以gitHub用戶:lyt-Python(組織名或者用戶名),fork 項目scrapy(https://github.com/scrapy/scrapy.Git)爲例子:github

一、clone 本身帳號裏fork的分支scrapy

git clone https://github.com/lyt-python/scrapy.git
cd scrapy  

二、增長遠程原始分支到本地(能夠用 git remote -v 命令查看遠程分支列表)fetch

git remote -v  
origin  https://github.com/lyt-python/scrapy.git (fetch)  
origin  https://github.com/lyt-python/scrapy.git (push)  

若是沒有遠程原始分支則須要增長:spa

git remote add scrapy https://github.com/scrapy/scrapy.git  

查看確認遠程分支列表:.net

git remote -v  
origin  https://github.com/lyt-python/scrapy.git (fetch)  
origin  https://github.com/lyt-python/scrapy.git (push)  
scrapy  https://github.com/scrapy/scrapy.git (fetch)  
scrapy  https://github.com/scrapy/scrapy.git (push)  

三、fetch原始源分支的新版本到本地code

git fetch scrapy  

會有以下信息:rem

  1. remote: Counting objects: 2147, done.  
  2. remote: Compressing objects: 100% (11/11), done.  
  3. remote: Total 2147 (delta 1280), reused 1280 (delta 1280), pack-reused 856  
  4. Receiving objects: 100% (2147/2147), 490.60 KiB | 39.00 KiB/s, done.  
  5. Resolving deltas: 100% (1585/1585), completed with 204 local objects.  
  6. From https://github.com/scrapy/scrapy  
  7.  * [new branch]      0.12       -> scrapy/0.12  
  8.  * [new branch]      0.14       -> scrapy/0.14  
  9. ...
  10.  * [new tag]         1.2.0dev2  -> 1.2.0dev2  

    四、合併兩個版本的代碼get

git merge scrapy/master  

會有以下信息:

  1. Updating a5db7f8..ebef6d7  
  2. Fast-forward  
  3.  .bumpversion.cfg                                   |   2 +-  
  4.  .travis.yml                                        |   7 +-  
  5.  CODE_OF_CONDUCT.md                                 |  50 ++++  
  6. ...
  7. ...
  8.  create mode 100644 scrapy/xlib/pydispatch.py  
  9.  create mode 100644 tests/test_pydispatch_deprecated.py  

五、把最新的代碼提交到github本身(lyt-python)的帳號上

git push origin master  

會有以下信息:

 

  1. Counting objects: 1802, done.  
  2. Delta compression using up to 24 threads.  
  3. Compressing objects: 100% (558/558), done.  
  4. Writing objects: 100% (1802/1802), 280.30 KiB | 0 bytes/s, done.  
  5. Total 1802 (delta 1395), reused 1644 (delta 1241)  
  6. To https://github.com/lyt-python/scrapy.git  
  7.    a5db7f8..ebef6d7  master -> master  
相關文章
相關標籤/搜索