1

I am cleaning a git repository's pull requests (PR). There was one PR created to merge a branch B, which was later considered deprecated and removed before being merged. As a result, branch B was deleted, and this PR is not showing up in Bitbucket's pull request list. However, if I use git show-ref, this PR is in the ref list as well as in the remote repository history. Is there a way to clear this PR in the remote repository?

master branch
|
|
|   * branch B, Pull Request
|   |
|   /
|  /
| /
|/
*
|
|

Additions: This PR exists in the remote repository. I could make a bare copy to local and remove the local PR with git reflog expire --expire=now --all && git gc --prune=now --aggressive, but don't know how to remove this PR in remote repository.

I got this problem when I was cleaning repository history using BFG as discussed here. My push of local changes to remote was rejected due to rejected refs (as shown below, and here is a related discussion on this topic)

(base) ****@*****:~/*****/abcde.git$ git push --force
Username for *****************:
Password for *****************:
Counting objects: 17811, done.
Delta compression using up to 24 threads.
Compressing objects: 100% (10604/10604), done.
Writing objects: 100% (17811/17811), 367.27 MiB | 2.16 MiB/s, done.
Total 17811 (delta 6545), reused 17811 (delta 6545)
remote: Resolving deltas: 100% (6545/6545), done.
remote: You are attempting to update refs that are reserved for Bitbucket's pull request functionality. Bitbucket manages these refs automatically, and they may not be updated by users.
remote: Rejected refs:
remote:         refs/pull-requests/2/from
remote:         refs/pull-requests/2/merge
remote:         refs/pull-requests/5/from
remote:         refs/pull-requests/5/merge
remote:

Updates:

Finally I bypassed the ref-conflict issue by creating a new empty remote repository and pushed my local git mirror there.

cd ~/<repo_directory/repo_name>
git remote set-url origin <bitbucket_URL>
git push --mirror
Ken S
  • 315
  • 1
  • 3
  • 11
  • 1
    Only whoever actually controls the remote repository can remove the pull request from it. As far as I know there is no "delete pull request request", so you'll have to send email to whoever controls it, rather than having the web-hosting site send the email. (It's possible that they can't delete it either and only the bitbucket admins can delete it, but that's between them and the folks running the bitbucket servers.) – torek Nov 05 '20 at 13:30
  • I think you are right that it needs admin level to deleted the pull requests. However my problem maybe a bit different. In the original repository (a lot of restructuring work has been done to my current version) I could see the PR in Bitbuket PR list. However, after the corresponding branch was deleted, the PR cannot be seen in the Bitbucket PR list anymore. – Ken S Nov 05 '20 at 14:07

3 Answers3

1

Is there a way to clear this PR in the remote repository?

According to your log,

remote: Resolving deltas: 100% (6545/6545), done.
remote: You are attempting to update refs that are reserved for Bitbucket's pull request functionality. Bitbucket manages these refs automatically, and they may not be updated by users.
remote: Rejected refs:
remote:         refs/pull-requests/2/from
remote:         refs/pull-requests/2/merge
remote:         refs/pull-requests/5/from
remote:         refs/pull-requests/5/merge

Bitbucket won't let you touch those refs via Git. How to get them removed is a question for Bitbucket support. See this discussion of the semantics for what looks like authoritative background.

jthill
  • 55,082
  • 5
  • 77
  • 137
0

Make sure you have deleted the branch and not just the PR. If the ref is showing up on your local you can run git fetch --prune to remove an refs on local that are not on your remote. You might also want to run git gc to remove orphaned objects as a followup.

TheGeorgeous
  • 3,927
  • 2
  • 20
  • 33
  • The branch was deleted, problem is that PR remains in the remote repository. Locally removing this PR is not a problem. I have updated my post above. – Ken S Nov 05 '20 at 04:26
0

I finally solved the ref issue with the following command:

git show-ref | cut -d' ' -f2 | grep 'pull-request' | xargs -r -L1 git update-ref -d

and confirmed the cleaning with:

git show-ref
Ken S
  • 315
  • 1
  • 3
  • 11