I received a pull request and I want to approve it via the command line (i.e., without logging into Github with my browser and using the GUI). This PR makes changes to a branch.
This is what I tried:
# First I go to the correct branch:
git checkout branch-to-be-modified
# Then I pull the changes made by the person who's contributing with the PR:
git pull https://github.com/my-contributor/code.git his-branch
# I then run `git status`, but it shows me nothing
git status
# Outputs:
# > On branch branch-to-be-modified
# > nothing to commit, working tree clean
How do I accept the Github pull request through the command line?
What else do I need to do, should I just git push origin branch-to-be-modified?
This should be easy, but I can't find this information. Thank you so much for any leads
You should ask GitHub to merge said pull request: that would be "accepting" it.
You can do so from command-line, using gh, the official GitHub client
See gh pr merge
gh pr merge <number>
But that supposes that you did login first (for instance, using a token like your PAT: gh auth login --with-token < mytoken.txt).
Again, from command-line, without using GitHub web directly.
But what if you want to accept WITHOUT merging, i.e. in the case of having multiple reviewers?
Then you would need to use gh pr review:
# approve the pull request of the current branch
gh pr review --approve
That way, you can approve the pull request indicating that you are satisfied with the changes, while still leaving it open for other reviewers to provide their feedback before it gets merged.
And, if you are part of a team project on GitHub, you might have protected branches set up which require multiple reviews before a pull request can be merged.
In such setups, individual approvals can be done using the GitHub CLI as shown above, and the pull request will only be able to be merged once it has received the required number of approvals.
Pull Requests are a Github-specific feature. Git is independent of Github, you won't find any Github-specific features in Git. If you want to accept PRs without a web browser you need to look for a Github tool such as Github Desktop or Github CLI. These are all wrappers around the Github REST API and Github GraphQL API.
You can merge the PR branch manually by treating it like any other remote branch, and the PR should recognize its branch has been merged. However Pull Requests can be about a lot more than just merging so you probably want to go with a Github tool.
Each project can merge their Pull Requests in different ways: merge, squash merge, or rebase. You would have to emulate the project's merge strategy. Fortunately, a Git PR will tell you how to do that: next to the Merge pull request button there is a link to "view command line instructions".

Click that and follow the instructions.
The general idea is to:
For more read Working With Remotes in Pro Git and Working With Forks on Github.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With