如何在Github上創(chuàng)建一個拉取請求
學(xué)習(xí)如何復(fù)刻一個倉庫,進(jìn)行更改,并要求維護人員審查并合并它。
你知道如何使用 git 了,你有一個 GitHub 倉庫并且可以向它推送。這一切都很好。但是你如何為他人的 GitHub 項目做出貢獻(xiàn)? 這是我在學(xué)習(xí) git 和 GitHub 之后想知道的。在本文中,我將解釋如何復(fù)刻一個 git 倉庫、進(jìn)行更改并提交一個拉取請求。
當(dāng)你想要在一個 GitHub 項目上工作時,第一步是復(fù)刻一個倉庫。

Forking a GitHub repo
你可以使用我的演示倉庫試一試。
當(dāng)你在這個頁面時,單擊右上角的 “Fork”(復(fù)刻)按鈕。這將在你的 GitHub 用戶賬戶下創(chuàng)建我的演示倉庫的一個新副本,其 URL 如下:
https://github.com/<你的用戶名>/demo
這個副本包含了原始倉庫中的所有代碼、分支和提交。
接下來,打開你計算機上的終端并運行命令來克隆倉庫:
git clone https://github.com/<你的用戶名>/demo
一旦倉庫被克隆后,你需要做兩件事:
1、通過發(fā)出命令創(chuàng)建一個新分支 new_branch :
git checkout -b new_branch
2、使用以下命令為上游倉庫創(chuàng)建一個新的遠(yuǎn)程:
git remote add upstream https://github.com/kedark3/demo
在這種情況下,“上游倉庫”指的是你創(chuàng)建復(fù)刻來自的原始倉庫。
現(xiàn)在你可以更改代碼了。以下代碼創(chuàng)建一個新分支,進(jìn)行任意更改,并將其推送到 new_branch 分支:
$ git checkout -b new_branchSwitched to a new branch ‘new_branch’$ echo “some test file” > test$ cat testSome test file$ git statusOn branch new_branchNo commits yetUntracked files:(use "git add <file>..." to include in what will be committed)testnothing added to commit but untracked files present (use "git add" to track)$ git add test$ git commit -S -m "Adding a test file to new_branch"[new_branch (root-commit) 4265ec8] Adding a test file to new_branch1 file changed, 1 insertion(+)create mode 100644 test$ git push -u origin new_branchEnumerating objects: 3, done.Counting objects: 100% (3/3), done.Writing objects: 100% (3/3), 918 bytes | 918.00 KiB/s, done.Total 3 (delta 0), reused 0 (delta 0)Remote: Create a pull request for ‘new_branch’ on GitHub by visiting:Remote: <http://github.com/example/Demo/pull/new/new\_branch>Remote:* [new branch] new_branch -> new_branch
一旦你將更改推送到您的倉庫后, “Compare & pull request”(比較和拉取請求)按鈕將出現(xiàn)在GitHub。

GitHub's Compare & Pull Request button
單擊它,你將進(jìn)入此屏幕:

GitHub's Open pull request button
單擊 “Create pull request”(創(chuàng)建拉取請求)按鈕打開一個拉取請求。這將允許倉庫的維護者們審查你的貢獻(xiàn)。然后,如果你的貢獻(xiàn)是沒問題的,他們可以合并它,或者他們可能會要求你做一些改變。
精簡版
總之,如果您想為一個項目做出貢獻(xiàn),最簡單的方法是:
- 找到您想要貢獻(xiàn)的項目
 - 復(fù)刻它
 - 將其克隆到你的本地系統(tǒng)
 - 建立一個新的分支
 - 進(jìn)行你的更改
 - 將其推送回你的倉庫
 - 單擊 “Compare & pull request”(比較和拉取請求)按鈕
 - 單擊 “Create pull request”(創(chuàng)建拉取請求)以打開一個新的拉取請求
 
如果審閱者要求更改,請重復(fù)步驟 5 和 6,為你的拉取請求添加更多提交。
快樂編碼!















 
 
 







 
 
 
 