Missed Team ’24? Catch up on announcements here.

×
Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

How to remove refs on remote git repo

CPJ
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
September 11, 2019

We have a git repo on bitbucket server that has some refs we need to delete.
I can view the remote refs by calling:

git ls-remote --refs | grep pull-requests

Giving:

634746a29a3a077254960538a3fbc421a174d68b refs/pull-requests/426/merge
fe80ad1e8d34fab4bb599595c9c584bdbca33125 refs/pull-requests/450/from
...
764a8d6d4d307c7a1b57bcde76ef9fde140f3562 refs/pull-requests/614/from
1fba4de34e609d3dc33c092d39af0d4ad13030e1 refs/pull-requests/614/merge

These pull requests don't actually exist in bitbucket (i.e. Don't show up as real pull requests). The numbers for the pull requests mark them as being really old too, years old. So we need to delete them. So when I try removing one of those dangling refs, for instance:

git push --delete origin refs/pull-requests/364/from

Bitbucket returns an error message stating:

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/364/from remote:

First question: Why is Bitbucket being so damned fussy on this issue? It's my git repo, I want those deleted.

Second question: Am I calling the correct command to remove the remote ref? 

1 answer

0 votes
Fabio Pires
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
May 18, 2022

Hey @CPJ , sorry for reviving this 3yo topic, but: have you found a solution?

Cheers

adityeah
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
August 2, 2022

Hey @Fabio Pires , @CPJ , have any of you found a solution to this?

Fabio Pires
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
August 2, 2022

Well, I basically renamed the repo to something like "reponame-old", created a new repo with the same name, and did something along the lines of:

  • git clone --quiet --bare ssh://git@.../reponame-old
  • cd reponame-old
  • git push --quiet --mirror ssh://git@.../newrepo.git
adityeah
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
August 3, 2022

Thanks, what worked for us was that we selectively pushed the references - that is, skip pushing the problematic references while pushing everything else. 

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events