# Review a Pull Request

> Take a pull request from its number or link to a running app you can click through, then remove it once it merges.

By the end of this guide, you'll have a pull request open in your editor and running on its own port, with its diff in front of you, and a way to remove it once it merges. Reading a diff tells you what changed, while running the branch tells you whether it works, and this is the workflow Testlane was built for.

## Before you start

You'll need two things:

- A [configured project](https://testlane.dev/docs/configuration/overview) with a `[commands.dev]` entry and `default_branch` set, like the one in [Quick start](https://testlane.dev/docs/getting-started/quick-start). We'll call it `my-project`.
- The number or the link of a pull request. We'll use `42`.

## Review it

::steps{level="3"}

### Open it in your editor

```bash
testlane my-project 42 code
```

```
→ cloning git@github.com:my-org/my-project.git (bare, partial)
→ fetching pull/42 → pr/42
→ worktree ready: /home/you/dev/testlane/my-project/trees/pr-42
→ opening in code
```

Testlane reads `42` as a pull request, fetches it into a workspace of its own and opens that in your editor. Running it again reuses the workspace, so it takes a moment rather than a fetch.

If you have the link rather than the number, paste the whole URL in place of the project and the ref:

```bash
testlane https://github.com/my-org/my-project/pull/42 code
```

Testlane finds the project whose `repo` has the same host, owner and name, and takes `42` from the `/pull/42` part.

### Run it

```bash
testlane my-project 42 run dev
```

```
→ worktree ready (reused)
→ running setup
…
listening on 4164
```

It's the same workspace. `run` runs your `[setup]` install first, and only when the files in `setup.cache_key` have changed, then starts your dev server on the workspace's own port. If you need another port for this run only, add `--port`, like `testlane my-project 42 run dev --port 6000`.

Two pull requests at once work too, since each workspace holds its own ports. [Run dev servers in parallel](https://testlane.dev/docs/guides/run-dev-servers-in-parallel) shows how.

### Read the diff

```bash
testlane my-project 42 diff --stat
```

```
 login.txt | 1 +
 1 file changed, 1 insertion(+)
```

With `gh` installed and signed in, a plain `diff` shows `gh pr diff`, which compares against the pull request's real base. With `--stat`, with extra `git diff` flags after `--` or without `gh`, it runs `git diff <merge-base>...HEAD` in the workspace, where the merge base is the one with `origin/<default_branch>`. To use your own difftool, add `--tool`, which always runs `git difftool` locally.

### Try things in it

```bash
testlane my-project 42 shell                                # a shell in the workspace
testlane my-project 42 exec -- pnpm test                    # one command, run without a shell
testlane my-project 42 exec --no-setup -- git log --oneline -5
```

`shell` and `exec` export the same variables your configured commands get, like `$TESTLANE_PORT`, `$TESTLANE_PATH` and `$TESTLANE_DATA_DIR`, so what you run by hand sees what `run dev` sees. `--no-setup` skips the install for a command that doesn't need it.

### Pick up new commits

When the author pushes a fix, bring the workspace up to date:

```bash
testlane my-project 42 sync
```

```
→ fetching pull/42
→ 05cc56ae → 6e1c1243, 3 file(s) changed
```

`sync` refuses to touch a workspace with uncommitted changes, so you decide what happens to them with `--stash` or `--discard`. [Refresh a workspace](https://testlane.dev/docs/guides/refresh-a-workspace) covers both, and `--fresh` for starting a workspace over.

### Clean up once it merges

```bash
testlane my-project clean --closed
```

`clean --closed` picks the workspaces whose pull request is closed or merged. It prints its plan and asks before it removes anything. [Clean up workspaces](https://testlane.dev/docs/guides/clean-up-workspaces) has the other filters, and a habit worth keeping.

::

## Review a pull request from a fork

A pull request from a fork opens the same way, since Testlane fetches `refs/pull/<n>/head` from your own remote. With `gh` signed in, Testlane also sets up push-back when it creates the workspace, so `git push` sends your commits to the contributor's branch.

Without `gh`, checkout still works on GitHub and GitHub Enterprise, which publish `refs/pull/<n>/head`. You lose the pull request's state, title and push-back, though. Run `testlane doctor` to see whether `gh` is found and signed in.

## Where to go next

Here's where to take it from here:

- [Workspace verbs](https://testlane.dev/docs/cli/workspace-verbs) lists every flag of `code`, `run`, `diff`, `exec`, `shell` and `sync`.
- [Refs](https://testlane.dev/docs/concepts/refs) lists every form a ref can take, in the order Testlane tries them.
- [Run dev servers in parallel](https://testlane.dev/docs/guides/run-dev-servers-in-parallel) shows how two pull requests run side by side.
