Search code examples
gitgit-branchpull-requestbfg-repo-cleanergit-clean

Rejected refs in repo-cleaning


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

Solution

  • 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.