
A pull request is a way for you to submit a request to have a branch in a repository to be merged into another branch, typically the "main" or "master" branch of the repository.
For example, let's say you use the git clone command to clone a repository.
git clone ssh://git@github.com/foo.git
And let's say the git branch command shows that you are on the master branch.
~]$ git branch --all
* master
remotes/origin/HEAD -> origin/master
remotes/origin/master
You will typically start by creating a new branch.
~]# git checkout -b feature/foo
Switched to a new branch 'feature/foo'
And then you make some change to a file and use the git commit command to commit the change.
git commit --message 'my message' bar.txt
And use git push to push the change to HEAD.
git push origin HEAD
You can now create a pull request to ask for your branch (feature/foo in this example) to be merged into another branch, almost ways the "main" or "master" branch.
If you are using GitHub this can be done using the gh pr create command. But first, you must use the gh auth login command to log into GitHub. Check out my article FreeKB - GitHub - Log into GitHub using the gh auth login command.
gh auth login
The gh pr create command can then be used to create a pull request. In this example, a pull request is created to ask for your feature/foo branch to be merged into the main branch and --dry-run is used to see what should be done without actually creating the pull request.
gh pr create --head "feature/foo" --base "main" --title "my Title" --body "my Message" --dry-run
The --repo option can be used if you want to create a pull request is a specific repo.
gh pr create --head "feature/foo" --base "main" --title "my Title" --body "my Message" --repo 'github.com/my_org/my_repo'
The gh pr list command can then be used to list the pull request. It's probably a good idea to use the --state all option to display all pull requests.
~]$ gh pr list --state all
Showing 2 of 2 pull requests in johndoe/my_repo that match your search
ID TITLE BRANCH CREATED AT
#2 merge the feature/bar branch into the main branch feature/bar about 11 minutes ago
#1 merge the feature/foo branch into the main branch feature/foo about 5 days ago
This should also notify the reviewers of the pull request to review the pull request. If the reviewers approve the pull request, then you should be able to merge the branch. The gh pr merge command can be used to merge an approved pull request.
gh pr merge --merge
Did you find this article helpful?
If so, consider buying me a coffee over at