0

Background: I file pull requests to an upstream repo. After those PRs are merged/closed, I want to delete the remote branches on my forked repo (origin) that served those PRs. I want to do this in one swoop from the command line.

I can do this for my local branches with:

gh pr list -A <author> -s merged --json 'headRefName' | jq -r '.[].headRefName' | tr -d '\r' | xargs git branch -d

I would think that this parallel code would work to delete the remote branches:

gh pr list -A <author> -s merged --json 'headRefName' | jq -r '.[].headRefName' | tr -d '\r' | xargs git push origin --delete

But this doesn't work. All the remote branches are still there. Here is the output I receive on the terminal:

error: unable to delete 'patch-45': remote ref does not exist error: unable to delete 'patch-44': remote ref does not exist error: unable to delete 'patch-42': remote ref does not exist error: unable to delete 'patch-41': remote ref does not exist error: unable to delete 'patch-40': remote ref does not exist error: unable to delete 'patch-38': remote ref does not exist error: unable to delete 'patch-36': remote ref does not exist error: failed to push some refs to 'https://github.com//content.git'

And if I run this to get a list of merged remote branches:

gh pr list -A <author> -s merged --json 'headRefName' | jq -r '.[].headRefName' | tr -d '\r'

Then my output is:

enter image description here

Any ideas how to make it work? Thanks

OS: Windows 10
Terminal: Git Bash

Pound Hash
  • 453
  • 1
  • 4
  • 13

0 Answers0