cli / cli/cli

`gh pr checkout` adds commits to current branch

Open
#8,383 5 comments 1 reaction 0 assignees View on GitHub
bug priority-2
Dominant language
Go
Stars
46.3k
Forks
9k
Avg merge
2d 9h
Merged PRs (30d)
89

Description

### Describe the bug

```
gh version 2.32.1 (2023-07-24)
https://github.com/cli/cli/releases/tag/v2.32.1
```

In a scenario where a PR that's being sent in from a remote which has the same branch name as the the branch it's being merged into, the commits that are pulled using `gh pr checkout` are added to the current active branch instead of a new branch being made.

### Steps to reproduce the behavior

1. Take PR https://github.com/laravel/cashier-paddle/pull/205
2. Clone the `laravel/cashier-paddle` repo and checkout the `master` branch
3. Run `gh pr checkout 205`
4. The commits are added to the current active `master` branch instead of a new branch being created

### Expected vs actual behavior

I'd expect a new branch being created which is isolated and its HEAD targets the remote branch of the contributor's repo. Otherwise you could accidentally push to your repo's branch instead of the PR branch which is quite dangerous if the PR isn't ready yet.

### Logs

```
master $ gh pr checkout 205
From github.com:laravel/cashier-paddle
* branch refs/pull/205/head -> FETCH_HEAD
Updating 8958784..62e27e3
Fast-forward
src/Http/Controllers/WebhookController.php | 6 +++---
src/Transaction.php | 8 ++++++++
tests/Feature/WebhooksTest.php | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 62 insertions(+), 3 deletions(-)
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.