Skip to content

Latest commit

 

History

History
199 lines (106 loc) · 6.68 KB

File metadata and controls

199 lines (106 loc) · 6.68 KB

PR (Pull Request) Tutorial

English Version

First, let's talk about when you can use a PR (Pull Request).

  • Scenario 1

You see a great project on the internet and you really want to contribute to it. At this time, you can use the PR mechanism.

Usually, you won't have permission for this project, so you must Fork the project to your own repo for modification -> After modification, push it back to your own branch

-> Then send a PR to the corresponding original project (pay attention to the other party's and your own branch) -> Wait for the author to test and feel that there is no problem before merging into the main branch

-> Congratulations on contributing to the community 😄

  • Scenario 2

The company can also use the PR model for multi-person development, but usually in this case you will have project permissions (different from scenario 1), so you

don't need to Fork. Just open a branch and send a PR to a specific branch (maybe develop).

Scenario 1 and Scenario 2 are basically the same concept. The only difference is whether you have repo permissions. If not, you need to Fork.

Today, I will mainly use Scenario 2 to briefly introduce the operation of PR.

github PR (Pull Request) tutorial

Using the concept of Git-Flow Basic Tutorial for teaching.

To make it simpler, there are only main(master), develop, and feature branches here.

Today, a requirement has come up. I will first open a feature branch from develop.

Assuming the requirement is done, I will push the feature branch up and start sending a PR.

Now I want to send a PR to develop. The branch to be sent is feature. (As shown below)

alt tag

After selecting, you can press Create pull request.

Then you will see a PR under the project.

alt tag

At this time, it may be the technical lead (depending on the company's process) who sees this PR. If there are no problems,

you can choose which type of Merge pull request to use.

alt tag

There are three types of Merge pull request to choose from:

  • Create a Merge Commit

This is basically a normal merge, but I usually don't like it because there will be meaningless merge commits.

  • Squash and Merge

This is for when you have a feature that took a total of 10 commits to complete, but these commits

don't actually have too much important information. At this time, you can choose to use the Squash method to merge these 10 commits into

one commit. (The other commits will become your message).

  • Rebase and Merge

The difference between this and Create a Merge Commit is that it will not have meaningless merge commits. It has the concept of grafting.

If you have 3 commits on your branch, after merging with this method, there will be 3 more commits.

As for which one to use, it depends on the needs of each company 😄

After deciding on the Merge pull request method, you can press it directly. You will see that it shows Merged.

And you can also choose whether to delete the branch and revert this PR.

alt tag

Basically, the whole process is like this. The concept of develop sending a PR to main is the same.

github CLI PR tutorial

If you have read the previous articles, you will feel that it is very troublesome 😑

Because you have to manually click on the webpage every time. Engineers must use the CLI.

Today I will teach you this github CLI 😆

You don't even need to open the GitHub webpage 😆

First is the installation method:

https://github.com/cli/cli/blob/trunk/docs/install_linux.md

Next is the login method gh_auth_login

gh auth login

Just choose the login method you want.

By the way, the documentation for github CLI is very well written. You can refer to its documentation and play with it GitHub CLI document.

Next, let's experience the power of github CLI 😆

Now there is a feature_cli branch. After pushing the branch,

(Friendly reminder ❗ ❗ To send a PR, this branch must be pushed to the remote)

(That is to say, you cannot send a PR that only exists locally but not on the remote)

(If you only want to PR a specific commit, please use git checkout -b [branch] [commit_id] and then send the PR)

You can send a PR through github CLI. To send a PR to the develop branch, the command is as follows:

The documentation can be found at https://cli.github.com/manual/gh_pr_create

gh pr create --base develop --head feature_cli

If you are currently on the feature_cli branch, you can also just enter:

gh pr create --base develop

Successfully sent a PR through github CLI.

alt tag

There is indeed this PR on GitHub.

alt tag

You can also use some of its commands:

gh pr create --base dev -a @me -l bug -r twtrubiks

-a means to assign this pr to yourself

-l sets the label to bug

-r sets the reviewer to twtrubiks

In addition to sending PRs, you can also accept PRs through github CLI. The command is as follows:

The documentation can be found at https://cli.github.com/manual/gh_pr_merge

gh pr merge -s 2

Parameter description:

-m Create a Merge Commit.

-s Squash and Merge.

-r Rebase and Merge.

The number 2 represents the PR number to be merged.

alt tag

This PR has indeed been merged on GitHub.

alt tag

You can also create an issue gh_issue_create

gh issue create -a @me -l bug

-a means to assign this issue to yourself

-l sets the label to bug

There are many other commands, so I won't introduce them one by one. Please study them yourself ☺️

Basically, the github CLI function is very powerful 😄

Others

The default editor for gh is nano. The following command changes it to vim:

gh config set editor vim