Skip to content

Add a gh pr update command corresponding to the API call / button on the Web UI #8426

Description

@tgoodsell-tempus

Describe the feature or problem you’d like to solve

The GH web interface and REST API support a PR "update" function, which does a merge or a rebase, with the rest API only supporting the merge commit option.

See: Keeping You Pull Request In Sync

It would be nice to have this function available in the CLI toolkit, meaning the direct GH API version of this, not a pseudo-update via doing the various git syncing and updating locally.

Proposed solution

Introduce a gh pr update command which:

  • Leverages the GH REST API version of this: Update A Pull Request Branch
    • The GraphQL API appears to support both the rebase and merge options, see: Update Pull Request Branch, this could be a good alternative to the REST API provided the maintainers are OK with using it over the REST call.
  • After the update is performed and the API tells us it's succeeded, pull/sync the local branch with the changed upstream branch

Additional context

As mentioned above, my personal preference is the update itself occurs using the API object, instead of doing the local only version of a merge/rebase on the base branch. Since I'm trying to mimic the Web UI button, the reasons that exists versus Github telling us to "get good" at doing branch updates I would apply to this command as well.

Activity

  1. added
    discussFeature changes that require discussion primarily among the GitHub CLI team
    on Dec 6, 2023
  2. maco commented on Dec 18, 2023

    @maco

    And a benefit of it doing it using the GH API instead of locally is that when you do it in the GH UI, it doesn't clear your approvals, whereas if you update the branch locally and push, I'm pretty sure it does.

  3. williammartin commented on Jan 19, 2024

    @williammartin
    Member

    Hey @tgoodsell-tempus, thanks for opening this and sorry about the slow response, December was a busy time and then we were into the holidays. We're catching up on untriaged issues at the moment.

    I think some of the behaviour you're describing can be emulated with gh repo sync but I can definitely see why it would be natural to find an equivalent to the UI under gh pr as a first class pr behaviour.

    The REST API equivalent to the GQL mutation would appear to be https://docs.github.com/en/rest/pulls/pulls?apiVersion=2022-11-28#update-a-pull-request-branch.

    We're a bit hesitant to make changes around gh pr at the moment because there's so many issues and it might be that the whole command needs a bit of a redesign. On the other hand, this one feels fairly straightforward and self-contained so maybe we'll open it up to community contributions. I'll discuss with the team!

  4. andyfeller commented on Jan 19, 2024

    @andyfeller
    Contributor

    And a benefit of it doing it using the GH API instead of locally is that when you do it in the GH UI, it doesn't clear your approvals, whereas if you update the branch locally and push, I'm pretty sure it does.

    @maco : it is a little nuanced as it depends on how you setup branch protection rules and/or repository rulesets

    Dismiss stale pull request approvals when new commits are pushed and/or Require approval of the most recent reviewable push

    It sounds like you might have worked with some repositories that were inconsistently configured.

  5. added
    discussFeature changes that require discussion primarily among the GitHub CLI team
    and removed
    discussFeature changes that require discussion primarily among the GitHub CLI team
    on Jan 22, 2024
  6. williammartin commented on Jan 22, 2024

    @williammartin
    Member

    We discussed this and think it would be a good command to have. To me, it feels self contained and low risk. I'd be interested in opening this up to the community to implement. WDYT @andyfeller ?

  7. mxie commented on Jan 31, 2024

    @mxie
    Member

    We discussed this and think it would be a good command to have. To me, it feels self contained and low risk. I'd be interested in opening this up to the community to implement. WDYT @andyfeller ?

    Confirmed with Andy that we're good to let folks pick this up if they're interested!

  8. added and removed
    discussFeature changes that require discussion primarily among the GitHub CLI team
    on Jan 31, 2024
  9. babakks commented on Apr 10, 2024

    @babakks
    Member

    @williammartin @andyfeller @mxie I just pushed a PR to add the pr update command.

  10. jscarle commented on Jun 27, 2024

    @jscarle

    I so need this!

  11. williammartin commented on Jun 27, 2024

    @williammartin
    Member

    Good to know. It's on our backlog to give another review to. I would hope it'll be in the next release 2 weeks from now. 🤞

  12. williammartin commented on Jul 10, 2024

    @williammartin
    Member

    Acceptance Criteria

    Merge Commit

    Given I have a PR that is one or more commits behind the base branch
    And my cwd is in the repository containing that PR
    When I run gh pr update [<number> | <url> | <branch>]
    Then the remote PR branch is updated with a merge commit containing the commits in the base branch
    And I see a message that the PR branch has been updated on stdout

    Rebase

    Given I have a PR that is one or more commits behind the base branch
    And my cwd is in the repository containing that PR
    When I run gh pr update [<number> | <url> | <branch>] --rebase
    Then the remote PR branch is updated with the commits being rebased on those from the base branch
    And I see a message that the PR branch has been updated on stdout

    PR Branch is in fork

    Given I have a PR from a fork that is one or more commits behind the base branch
    And my cwd is in the repository containing that PR
    When I run gh pr update [<number> | <url> | <branch>]
    Then the remote PR branch is updated with a merge commit containing the commits in the base branch
    And I see a message that the PR branch has been updated on stdout

    Defaults to current branch

    Given I have a PR from a fork that is one or more commits behind the base branch
    And my cwd is in the repository containing that PR
    And the PR branch is currently checked out
    When I run gh pr update
    Then the remote PR branch is updated with a merge commit containing the commits in the base branch
    And I see a message that the PR branch has been updated on stdout

    Already Up To Date

    Given I have a PR that already contains all commits from the base branch
    And my cwd is in the repository containing that PR
    When I run gh pr update [<number> | <url> | <branch>]
    Then I see a message on stdout that the PR branch is already up-to-date

    Conflicts

    Given there are conflicts between the base branch and the PR branch
    And my cwd is in the repository containing that PR
    When I run gh pr update [<number> | <url> | <branch>]
    Then I see a helpful message that conflicts must be resolved first

    PR Not Found

    Given my cwd is in a repository that doesn't contain the PR I want to target
    When I run gh pr update [<number> | <url> | <branch>]
    Then I see a message that the PR could not be found

    Not in Repo

    Given my cwd is not in a git repository
    When I run gh pr update [<number> | <url> | <branch>]
    Then I see a message that the current dir couldn't be resolved to a repository

    Note, the currently implemented message here isn't very good but let's stick with it for consistency.

    Target different repo

    Given I have a PR that is one or more commits behind the base branch
    And my cwd is in a repository that doesn't contain the PR I want to target
    When I run gh pr update [<number> | <url> | <branch>] --repo <repo containing PR>
    Then the remote PR branch is updated with a merge commit containing the commits in the base branch
    And I see a message that the PR branch has been updated on stdout

    Target different repo, no arg

    When I run gh pr update --repo <any repo>
    Then I see a message that an argument must be provided when the --repo flag is used.

  13. williammartin commented on Jul 17, 2024

    @williammartin
    Member

    Acceptance Criteria

    1. Merge Commit

    Given I have a PR that is one or more commits behind the base branch
    And my cwd is in the repository containing that PR
    When I run gh pr update [<number> | <url> | <branch>]
    Then the remote PR branch is updated with a merge commit containing the commits in the base branch
    And I see a message that the PR branch has been updated on stdout

    ✓ Created repository williammartin/gh-8953-acceptance-1.sh on GitHub
      https://github.com/williammartin/gh-8953-acceptance-1.sh
    Cloning into 'gh-8953-acceptance-1.sh'...
    remote: Enumerating objects: 3, done.
    remote: Counting objects: 100% (3/3), done.
    remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
    Receiving objects: 100% (3/3), done.
    Switched to a new branch 'pr-branch'
    [pr-branch 662d69d] change in pr
     1 file changed, 1 insertion(+), 1 deletion(-)
    Enumerating objects: 5, done.
    Counting objects: 100% (5/5), done.
    Writing objects: 100% (3/3), 270 bytes | 270.00 KiB/s, done.
    Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
    remote:
    remote: Create a pull request for 'pr-branch' on GitHub by visiting:
    remote:      https://github.com/williammartin/gh-8953-acceptance-1.sh/pull/new/pr-branch
    remote:
    To https://github.com/williammartin/gh-8953-acceptance-1.sh.git
     * [new branch]      pr-branch -> pr-branch
    branch 'pr-branch' set up to track 'origin/pr-branch'.
    
    Creating pull request for pr-branch into main in williammartin/gh-8953-acceptance-1.sh
    
    https://github.com/williammartin/gh-8953-acceptance-1.sh/pull/1
    Switched to branch 'main'
    Your branch is up to date with 'origin/main'.
    [main c2e8901] change on main
     1 file changed, 1 insertion(+)
     create mode 100644 NEW.md
    Enumerating objects: 4, done.
    Counting objects: 100% (4/4), done.
    Delta compression using up to 10 threads
    Compressing objects: 100% (2/2), done.
    Writing objects: 100% (3/3), 295 bytes | 295.00 KiB/s, done.
    Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
    To https://github.com/williammartin/gh-8953-acceptance-1.sh.git
       999cf6e..c2e8901  main -> main
    branch 'main' set up to track 'origin/main'.
    Switched to branch 'pr-branch'
    Your branch is up to date with 'origin/pr-branch'.
    ✓ PR branch updated
    
    Details
    #!/usr/bin/env sh
    
    cli=/Users/williammartin/workspace/cli
    
    _tmp=/tmp
    _repo=gh-8953-acceptance-$(basename $0)
    _gh=$cli/bin/gh
    _pwd=$(pwd)
    
    cleanup () {
        cd $_pwd
        ARG=$?
        rm -rf "$_tmp/$_repo"
        gh repo delete --yes $_repo
        exit $ARG
    } 
    trap cleanup EXIT
    
    cd $_tmp
    $_gh repo create --clone --private --add-readme $_repo
    $_gh repo clone $_repo
    cd $_repo
    git checkout -b pr-branch
    echo "updated in pr branch" > README.md
    git commit -am 'change in pr'
    git push -u origin pr-branch
    $_gh pr create --fill --title "test" --body ''
    git checkout main
    touch NEW.md
    echo "new file on main" > NEW.md
    git add NEW.md
    git commit -am 'change on main'
    git push -u origin main
    git checkout pr-branch
    
    $_gh pr update
    

    Image showing a merge from main into pr branch


    2. Rebase

    Given I have a PR that is one or more commits behind the base branch
    And my cwd is in the repository containing that PR
    When I run gh pr update [<number> | <url> | <branch>] --rebase
    Then the remote PR branch is updated with the commits being rebased on those from the base branch
    And I see a message that the PR branch has been updated on stdout

    Details
    #!/usr/bin/env sh
    
    cli=/Users/williammartin/workspace/cli
    
    _tmp=/tmp
    _repo=gh-8953-acceptance-$(basename $0)
    _gh=$cli/bin/gh
    _pwd=$(pwd)
    
    cleanup () {
        cd $_pwd
        ARG=$?
        rm -rf "$_tmp/$_repo"
        gh repo delete $_repo
        exit $ARG
    } 
    trap cleanup EXIT
    
    cd $_tmp
    $_gh repo create --private --add-readme $_repo
    $_gh repo clone $_repo
    cd $_repo
    git checkout -b pr-branch
    echo "updated in pr branch" > README.md
    git commit -am 'change in pr'
    git push -u origin pr-branch
    $_gh pr create --fill --title "test" --body ''
    git checkout main
    touch NEW.md
    echo "new file on main" > NEW.md
    git add NEW.md
    git commit -am 'change on main'
    git push -u origin main
    git checkout pr-branch
    
    $_gh pr update --rebase
    

    Image showing a rebase of pr commit on main branch

    3. PR Branch is in fork

    Given I have a PR from a fork that is one or more commits behind the base branch
    And my cwd is in the repository containing that PR
    When I run gh pr update [<number> | <url> | <branch>]
    Then the remote PR branch is updated with a merge commit containing the commits in the base branch
    And I see a message that the PR branch has been updated on stdout

    ➜  8963-acceptance ./3.sh
    ✓ Created repository williammartin/gh-8953-acceptance-3.sh on GitHub
      https://github.com/williammartin/gh-8953-acceptance-3.sh
    Cloning into 'gh-8953-acceptance-3.sh'...
    ✓ Created fork williammartin-test-org/gh-8953-acceptance-3.sh
    ? Would you like to add a remote for the fork? No
    Cloning into 'gh-8953-acceptance-3.sh-fork'...
    remote: Enumerating objects: 3, done.
    remote: Counting objects: 100% (3/3), done.
    remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
    Receiving objects: 100% (3/3), done.
    From https://github.com/williammartin/gh-8953-acceptance-3.sh
     * [new branch]      main       -> upstream/main
    ! Repository williammartin/gh-8953-acceptance-3.sh set as the default repository. To learn more about the default repository, run: gh repo set-default --help
    Switched to a new branch 'pr-branch'
    [pr-branch 3f56d9d] change in pr
     1 file changed, 1 insertion(+), 1 deletion(-)
    Enumerating objects: 5, done.
    Counting objects: 100% (5/5), done.
    Writing objects: 100% (3/3), 269 bytes | 269.00 KiB/s, done.
    Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
    remote:
    remote: Create a pull request for 'pr-branch' on GitHub by visiting:
    remote:      https://github.com/williammartin-test-org/gh-8953-acceptance-3.sh/pull/new/pr-branch
    remote:
    To https://github.com/williammartin-test-org/gh-8953-acceptance-3.sh.git
     * [new branch]      pr-branch -> pr-branch
    branch 'pr-branch' set up to track 'origin/pr-branch'.
    
    Creating pull request for williammartin-test-org:pr-branch into main in williammartin/gh-8953-acceptance-3.sh
    
    https://github.com/williammartin/gh-8953-acceptance-3.sh/pull/1
    /tmp/gh-8953-acceptance-3.sh
    [main 62e17c3] change on main
     1 file changed, 1 insertion(+)
     create mode 100644 NEW.md
    Enumerating objects: 4, done.
    Counting objects: 100% (4/4), done.
    Delta compression using up to 10 threads
    Compressing objects: 100% (2/2), done.
    Writing objects: 100% (3/3), 295 bytes | 295.00 KiB/s, done.
    Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
    To https://github.com/williammartin/gh-8953-acceptance-3.sh.git
       094d19e..62e17c3  main -> main
    branch 'main' set up to track 'origin/main'.
    Already on 'pr-branch'
    Your branch is up to date with 'origin/pr-branch'.
    ✓ PR branch updated
    
    Details
    #!/usr/bin/env sh
    
    cli=/Users/williammartin/workspace/cli
    
    _tmp=/tmp
    _repo=gh-8953-acceptance-$(basename $0)
    _gh=$cli/bin/gh
    _pwd=$(pwd)
    
    cleanup () {
        cd $_pwd
        ARG=$?
        rm -rf "$_tmp/$_repo"
        rm -rf "$_tmp/$_repo-fork"
        gh repo delete $_repo
        gh repo delete williammartin-test-org/$_repo
        exit $ARG
    } 
    trap cleanup EXIT
    
    cd $_tmp
    $_gh repo create --clone --private --add-readme $_repo
    cd $_repo
    $_gh repo fork --org williammartin-test-org
    cd $_tmp
    $_gh repo clone williammartin-test-org/$_repo "$_repo"-fork
    cd "$_repo-fork"
    git checkout -b pr-branch
    echo "updated in pr branch" > README.md
    git commit -am 'change in pr'
    git push -u origin pr-branch
    $_gh pr create --fill --title "test" --body ''
    echo $_tmp/$_repo
    cd "$_tmp/$_repo"
    touch NEW.md
    echo "new file on main" > NEW.md
    git add NEW.md
    git commit -am 'change on main'
    git push -u origin main
    cd "$_tmp/$_repo-fork"
    git checkout pr-branch
    
    $_gh pr update
    

    Image showing a PR from a fork that has a merge commit from main into the pr branch


    4. Defaults to current branch

    Given I have a PR from a fork that is one or more commits behind the base branch
    And my cwd is in the repository containing that PR
    And the PR branch is currently checked out
    When I run gh pr update
    Then the remote PR branch is updated with a merge commit containing the commits in the base branch
    And I see a message that the PR branch has been updated on stdout

    This is demonstrated by the previous examples by accident.


    5. Already Up To Date

    Given I have a PR that already contains all commits from the base branch
    And my cwd is in the repository containing that PR
    When I run gh pr update [<number> | <url> | <branch>]
    Then I see a message on stdout that the PR branch is already up-to-date

    ➜  8963-acceptance ./5.sh
    ✓ Created repository williammartin/gh-8953-acceptance-5.sh on GitHub
      https://github.com/williammartin/gh-8953-acceptance-5.sh
    Cloning into 'gh-8953-acceptance-5.sh'...
    remote: Enumerating objects: 3, done.
    remote: Counting objects: 100% (3/3), done.
    remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
    Receiving objects: 100% (3/3), done.
    Switched to a new branch 'pr-branch'
    [pr-branch 107cc09] change in pr
     1 file changed, 1 insertion(+), 1 deletion(-)
    Enumerating objects: 5, done.
    Counting objects: 100% (5/5), done.
    Writing objects: 100% (3/3), 269 bytes | 269.00 KiB/s, done.
    Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
    remote:
    remote: Create a pull request for 'pr-branch' on GitHub by visiting:
    remote:      https://github.com/williammartin/gh-8953-acceptance-5.sh/pull/new/pr-branch
    remote:
    To https://github.com/williammartin/gh-8953-acceptance-5.sh.git
     * [new branch]      pr-branch -> pr-branch
    branch 'pr-branch' set up to track 'origin/pr-branch'.
    
    Creating pull request for pr-branch into main in williammartin/gh-8953-acceptance-5.sh
    
    https://github.com/williammartin/gh-8953-acceptance-5.sh/pull/1
    ✓ PR branch already up-to-date
    
    Details
    #!/usr/bin/env sh
    
    cli=/Users/williammartin/workspace/cli
    
    _tmp=/tmp
    _repo=gh-8953-acceptance-$(basename $0)
    _gh=$cli/bin/gh
    _pwd=$(pwd)
    
    cleanup () {
        cd $_pwd
        ARG=$?
        rm -rf "$_tmp/$_repo"
        gh repo delete $_repo
        exit $ARG
    } 
    trap cleanup EXIT
    
    cd $_tmp
    $_gh repo create --private --add-readme $_repo
    $_gh repo clone $_repo
    cd $_repo
    git checkout -b pr-branch
    echo "updated in pr branch" > README.md
    git commit -am 'change in pr'
    git push -u origin pr-branch
    $_gh pr create --fill --title "test" --body ''
    
    $_gh pr update
    

    6. Conflicts

    Given there are conflicts between the base branch and the PR branch
    And my cwd is in the repository containing that PR
    When I run gh pr update [<number> | <url> | <branch>]
    Then I see a helpful message that conflicts must be resolved first

    ➜  8963-acceptance ./6.sh
    ✓ Created repository williammartin/gh-8953-acceptance-6.sh on GitHub
      https://github.com/williammartin/gh-8953-acceptance-6.sh
    Cloning into 'gh-8953-acceptance-6.sh'...
    remote: Enumerating objects: 3, done.
    remote: Counting objects: 100% (3/3), done.
    remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
    Receiving objects: 100% (3/3), done.
    Switched to a new branch 'pr-branch'
    [pr-branch 74b7e5c] change in pr
     1 file changed, 1 insertion(+), 1 deletion(-)
    Enumerating objects: 5, done.
    Counting objects: 100% (5/5), done.
    Writing objects: 100% (3/3), 270 bytes | 270.00 KiB/s, done.
    Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
    remote:
    remote: Create a pull request for 'pr-branch' on GitHub by visiting:
    remote:      https://github.com/williammartin/gh-8953-acceptance-6.sh/pull/new/pr-branch
    remote:
    To https://github.com/williammartin/gh-8953-acceptance-6.sh.git
     * [new branch]      pr-branch -> pr-branch
    branch 'pr-branch' set up to track 'origin/pr-branch'.
    
    Creating pull request for pr-branch into main in williammartin/gh-8953-acceptance-6.sh
    
    https://github.com/williammartin/gh-8953-acceptance-6.sh/pull/1
    Switched to branch 'main'
    Your branch is up to date with 'origin/main'.
    [main fe9f6ab] change on main (conflicting)
     1 file changed, 1 insertion(+), 1 deletion(-)
    Enumerating objects: 5, done.
    Counting objects: 100% (5/5), done.
    Delta compression using up to 10 threads
    Compressing objects: 100% (2/2), done.
    Writing objects: 100% (3/3), 314 bytes | 314.00 KiB/s, done.
    Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
    To https://github.com/williammartin/gh-8953-acceptance-6.sh.git
       23aa2d1..fe9f6ab  main -> main
    branch 'main' set up to track 'origin/main'.
    Switched to branch 'pr-branch'
    Your branch is up to date with 'origin/pr-branch'.
    X Cannot update PR branch due to conflicts
    
    Details
    #!/usr/bin/env sh
    
    cli=/Users/williammartin/workspace/cli
    
    _tmp=/tmp
    _repo=gh-8953-acceptance-$(basename $0)
    _gh=$cli/bin/gh
    _pwd=$(pwd)
    
    cleanup () {
        cd $_pwd
        ARG=$?
        rm -rf "$_tmp/$_repo"
        gh repo delete $_repo
        exit $ARG
    } 
    trap cleanup EXIT
    
    cd $_tmp
    $_gh repo create --private --add-readme $_repo
    $_gh repo clone $_repo
    cd $_repo
    git checkout -b pr-branch
    echo "updated in pr branch" > README.md
    git commit -am 'change in pr'
    git push -u origin pr-branch
    $_gh pr create --fill --title "test" --body ''
    git checkout main
    echo "modified in base branch to make it conflicting with the pr" > README.md
    git add README.md
    git commit -am 'change on main (conflicting)'
    git push -u origin main
    git checkout pr-branch
    
    $_gh pr update
    

    7. PR Not Found

    Given my cwd is in a repository that doesn't contain the PR I want to target
    When I run gh pr update [<number> | <url> | <branch>]
    Then I see a message that the PR could not be found

    ➜  8963-acceptance ./7.sh
    ✓ Created repository williammartin/gh-8953-acceptance-7.sh on GitHub
      https://github.com/williammartin/gh-8953-acceptance-7.sh
    Cloning into 'gh-8953-acceptance-7.sh'...
    remote: Enumerating objects: 3, done.
    remote: Counting objects: 100% (3/3), done.
    remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
    Receiving objects: 100% (3/3), done.
    no pull requests found for branch "main"
    
    Details
    #!/usr/bin/env sh
    
    cli=/Users/williammartin/workspace/cli
    
    _tmp=/tmp
    _repo=gh-8953-acceptance-$(basename $0)
    _gh=$cli/bin/gh
    _pwd=$(pwd)
    
    cleanup () {
        cd $_pwd
        ARG=$?
        rm -rf "$_tmp/$_repo"
        gh repo delete $_repo
        exit $ARG
    } 
    trap cleanup EXIT
    
    cd $_tmp
    $_gh repo create --private --add-readme $_repo
    $_gh repo clone $_repo
    cd $_repo
    
    $_gh pr update
    

    8. Not in Repo

    Given my cwd is not in a git repository
    When I run gh pr update [<number> | <url> | <branch>]
    Then I see a message that the current dir couldn't be resolved to a repository

    ➜  8963-acceptance ./8.sh
    failed to run git: fatal: not a git repository (or any of the parent directories): .git
    
    Details
    #!/usr/bin/env sh
    
    cli=/Users/williammartin/workspace/cli
    
    _tmp=/tmp
    _repo=gh-8953-acceptance-$(basename $0)
    _gh=$cli/bin/gh
    _pwd=$(pwd)
    
    cleanup () {
        cd $_pwd
        rm -rf "$_tmp/$_repo"
        exit $ARG
    } 
    trap cleanup EXIT
    
    mkdir "$_tmp/$_repo"
    cd "$_tmp/$_repo"
    
    $_gh pr update
    

    9. Target different repo

    Given I have a PR that is one or more commits behind the base branch
    And my cwd is in a repository that doesn't contain the PR I want to target
    When I run gh pr update [<number> | <url> | <branch>] --repo <repo containing PR>
    Then the remote PR branch is updated with a merge commit containing the commits in the base branch
    And I see a message that the PR branch has been updated on stdout

    ➜  8963-acceptance ./9.sh
    Cloning into 'gh-8953-acceptance-9.sh'...
    remote: Enumerating objects: 3, done.
    remote: Counting objects: 100% (3/3), done.
    remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
    Receiving objects: 100% (3/3), done.
    Switched to a new branch 'pr-branch'
    [pr-branch c95635b] change in pr
     1 file changed, 1 insertion(+), 1 deletion(-)
    Enumerating objects: 5, done.
    Counting objects: 100% (5/5), done.
    Writing objects: 100% (3/3), 270 bytes | 270.00 KiB/s, done.
    Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
    remote:
    remote: Create a pull request for 'pr-branch' on GitHub by visiting:
    remote:      https://github.com/williammartin/gh-8953-acceptance-9.sh/pull/new/pr-branch
    remote:
    To https://github.com/williammartin/gh-8953-acceptance-9.sh.git
     * [new branch]      pr-branch -> pr-branch
    branch 'pr-branch' set up to track 'origin/pr-branch'.
    Switched to branch 'main'
    Your branch is up to date with 'origin/main'.
    [main eba6d75] change on main
     1 file changed, 1 insertion(+)
     create mode 100644 NEW.md
    Enumerating objects: 4, done.
    Counting objects: 100% (4/4), done.
    Delta compression using up to 10 threads
    Compressing objects: 100% (2/2), done.
    Writing objects: 100% (3/3), 295 bytes | 295.00 KiB/s, done.
    Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
    To https://github.com/williammartin/gh-8953-acceptance-9.sh.git
       bafc685..eba6d75  main -> main
    branch 'main' set up to track 'origin/main'.
    Switched to branch 'pr-branch'
    Your branch is up to date with 'origin/pr-branch'.
    /Users/williammartin/workspace/cli/bin/gh pr update https://github.com/williammartin/gh-8953-acceptance-9.sh/pull/1 --repo https://github.com/williammartin/gh-8953-acceptance-9.sh
    ✓ PR branch updated
    
    Details
    #!/usr/bin/env sh
    
    cli=/Users/williammartin/workspace/cli
    
    _tmp=/tmp
    _repo=gh-8953-acceptance-$(basename $0)
    _gh=$cli/bin/gh
    _pwd=$(pwd)
    
    cleanup () {
        cd $_pwd
        ARG=$?
        rm -rf "$_tmp/$_repo"
        gh repo delete $_repo
        exit $ARG
    } 
    trap cleanup EXIT
    
    cd $_tmp
    repo=$($_gh repo create --private --add-readme $_repo)
    $_gh repo clone $_repo
    cd $_repo
    git checkout -b pr-branch
    echo "updated in pr branch" > README.md
    git commit -am 'change in pr'
    git push -u origin pr-branch
    pr=$($_gh pr create --fill --title "test" --body '')
    git checkout main
    touch NEW.md
    echo "new file on main" > NEW.md
    git add NEW.md
    git commit -am 'change on main'
    git push -u origin main
    git checkout pr-branch
    cd $_tmp
    
    echo "$_gh pr update $pr --repo $repo"
    $_gh pr update $pr --repo $repo
    

    10. Target different repo, no arg

    When I run gh pr update --repo <any repo>
    Then I see a message that an argument must be provided when the --repo flag is used.

    ➜  8963-acceptance ./10.sh
    flag needs an argument: --repo
    
    Usage:  gh pr update [<number> | <url> | <branch>] [flags]
    
    Flags:
      --rebase   Update PR branch by rebasing o
    
    Details
    #!/usr/bin/env sh
    
    cli=/Users/williammartin/workspace/cli
    
    _gh=$cli/bin/gh
    
    $_gh pr update --repo $repo
    
  14. williammartin commented on Jul 17, 2024

    @williammartin
    Member

    Just as a note, we agreed in #8953 that this would be pr update-branch to avoid some ambiguity with pr edit. Hope it solves your problems!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

enhancementa request to improve CLIgh-prrelating to the gh pr commandhelp wantedContributions welcome

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions