Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I test a pull request before merging it?

Tags:

git

github

I work as a part of a team. Our process is to create a separate branch, work on the separate branch, then push that branch to 'origin' and make a pull request to master.

I am trying to get better with the default command line Git.

Then another person makes a pull request on a branch. Is there an easy way to pull that branch to my local and check out the branch so I can test the code before approving the pull request?

like image 313
Steven Rogers Avatar asked Mar 23 '17 16:03

Steven Rogers


People also ask

How do I test a pull request locally before merging?

To check out a pull request locally, use the gh pr checkout subcommand. Replace pull-request with the number, URL, or head branch of the pull request.

How do I know if a pull request is merged?

Pull requests are closed automatically whenever the maintainer merge the changes through the web interface. If he merged using the command line, it will be closed as soon as he pushes the code back to Github. So if a PR is still open, it means it is not merged.


4 Answers

There's even the possibility of checking out the "remote branch" directly, no need to create a local branch (git will say you are working on detached HEAD state), so, using Sajib's example:

git fetch origin
git checkout origin/whatever
like image 195
eftshift0 Avatar answered Sep 22 '22 14:09

eftshift0


You can checkout the branch (say, feature) where pull request is created.

$ git fetch

# create a new branch 'test-feature' with 'origin/feature' history
$ git checkout -b test-feature origin/feature
# now test here

You can merge master into test-feature branch and test if all is ok!

$ git pull origin master
# test more
like image 20
Sajib Khan Avatar answered Sep 20 '22 14:09

Sajib Khan


First, you have to fetch branch:

git fetch origin

Then you can list all files that have been changed:

git diff --name-only origin/master 
like image 21
Krzysztof Atłasik Avatar answered Sep 19 '22 14:09

Krzysztof Atłasik


Disclaimer: I am the creator of Pull Dog, but I truly believe it solves this particular issue very well.

I made a GitHub app called Pull Dog. For every pull request you open, it takes your docker-compose.yml file, creates a new test environment, runs docker-compose up on it, opens the exposed ports in the firewall, and posts a link with connection details for each of these ports.

Portainer (15k stars on GitHub as of writing) is using it for their project. You can go look at any of their pull requests to see how it behaves.

Highlights:

  • Fully managed. No need to host anything.
  • Took me 47 seconds to set up for my own project.
  • Free plan available for the most basic needs, and cheap otherwise.
like image 38
Mathias Lykkegaard Lorenzen Avatar answered Sep 21 '22 14:09

Mathias Lykkegaard Lorenzen