Skip to content

pr checkout: allow recovering after a force-push #562

@allejo

Description

@allejo

Describe the feature or problem you’d like to solve

Rebasing is a common practice on my team for feature branches and therefore, we have a lot of force pushes in our PRs.

Process:

  • I had checked out this PR in the past to review/test it locally.
  • My colleague had made some updates and force pushed to the branch
  • I used gh to check out the branch again
  • I get an error
(develop) $ gh pr checkout 1
remote: Enumerating objects: 119, done.
remote: Counting objects: 100% (119/119), done.
remote: Compressing objects: 100% (34/34), done.
remote: Total 105 (delta 86), reused 90 (delta 71), pack-reused 0
Receiving objects: 100% (105/105), 9.93 KiB | 564.00 KiB/s, done.
Resolving deltas: 100% (86/86), completed with 12 local objects.
From github.com:my-org/repo
 + 458540d...f0b5ee1 feature/some-awesome-feature -> origin/feature/some-awesome-feature  (forced update)
Switched to branch 'feature/some-awesome-feature'
Your branch and 'origin/feature/some-awesome-feature' have diverged,
and have 10 and 26 different commits each, respectively.
  (use "git pull" to merge the remote branch into yours)
fatal: Not possible to fast-forward, aborting.
exit status 128

Proposed solution

Add a --reset flag to do a hard reset before trying to pull/check out the branch.

gh pr checkout 1 --reset

Additional context

N/A

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinggh-prrelating to the gh pr commandpriority-2Affects more than a few users but doesn't prevent core functions

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions