Skip to main content

Pull request

拉取請求可讓您通知其他貢獻者有關 Git 分支的變更。 拉取請求時,您可以先討論並評估建議的變更,然後再將變更執行到主分支。

您最終可以透過建立拉取請求,將變更合併回主儲存庫 (或 repo)。 但是,需要注意的是,在對原始代碼進行任何變更之前,GitHub 會創建一個 fork(或專案的副本),即使變更無法推送到另一個 repo,也可以將變更提交到 fork 副本。

任何人都可以透過拉取請求中的內嵌註解提出變更建議,但在合併變更之前只有擁有者有審查和批准變更的權利。 若要建立拉取請求:

  • Make changes to the file.

  • Change the proposal and complete a description of the change.

  • Click the Proposed File Change button to create a commit in the forked repo to send the change to the owner.

  • Enter comments about the change. If more context is needed about the change, use the text box.

  • Click Pull Request.

官方教學:Creating a pull request

您可以通過保留提交來合併拉取請求。 以下是您在合併拉取請求時可以使用的拉取請求合併選項清單。

  • Merge commits. All commits from the feature branch are added to the base branch in a merge commit using the -- no–ff option. 
  • Squash and merge commits. Multiple commits of a pull request are squashed, or combined into a single commit, using the fast-forward option. It is recommended that when merging two branches, pull requests are squashed and merged to prevent the likelihood of conflicts due to redundancy.
  • Merge message for a squash merge. GitHub generates a default commit message, which you can edit. This message may include the pull request title, pull request description, or information about the commits.
  • Rebase and merge commits. All commits from the topic branch are added onto the base branch individually without a merge commit. 
  • Indirect merges. GitHub can merge a pull request automatically if the head branch is directly or indirectly merged into the base branch externally.
Practice

Basic processes

  1. Fork the project you're interested in to your repository (via web)
    • Login to your GitHub repository
    • Visit the project: https://github.com/google/it-cert-automation-practice 
    •  Fork your own copy of this project via GitHub's website
  2. Clone the repository to local
    • git clone https://github.com/google/it-cert-automation-practice
    • cd it-cert-automation-practice
  3. Setup a remote for the upstream repo.
    • git remote -v
    • git remote add upstream https://github.com/google/it-cert-automation-practice
    • git remote -v
  4. Configure Git
    • git config --global user.name "Yourname"
    • git config --global user.email "your@email"
  5. Create new local branch for the fix 
    • git branch improve-username-behavior
    • git checkout improve-username-behavior
  6. Fix and test the code
  7. Commit the changes
    • git status 
    • git add . 
    • git commit 
    • git push origin improve-username-behavior
  8. Create a pull request (PR) (via web)
    1. Login to your forked repository
    2. Go to Pull requests > Create a pull request
    3. Edit the title and the description for the pull request