title: git delete remotes: remote refs do not exist
body: <h2>In short;</h2>
  
  <ul>
  <li>How can I delete remote multiple merged remotes?</li>
  </ul>
  
  <h2>More background;</h2>
  
  <p>I have a git repo with tens of remotes which have been merged into master.  I can delete these remotes one at a time by using:</p>
  
  <pre><code>git push --delete origin myBranch-1234
  </code></pre>
  
  <p>However this is a slow and tedious process for all remotes.  So I'm trying this command:</p>
  
  <pre><code>git branch -r --merged | grep origin | grep -v master | xargs git push origin --delete
  </code></pre>
  
  <p><code>git branch -r --merged</code> lists all merged remotes.<br>
  <code>grep origin</code> tells the command to include origin.<br>
  <code>grep -v master</code> tells the command to exclude master.<br>
  <code>xargs git push origin --delete</code> tells the command to delete the list of remotes.</p>
  
  <p>All together, I expect this to gather all merged remotes and delete them.</p>
  
  <p>When I run the above command, I receive the following for every merged remote;</p>
  
  <pre><code>error: unable to delete 'origin/myBranch-1234': remote ref does not exist
  error: unable to delete 'origin/myBranch-1235': remote ref does not exist
  error: unable to delete 'origin/myBranch-1236': remote ref does not exist
  error: unable to delete 'origin/myBranch-1237': remote ref does not exist
  ... etc
  </code></pre>
  
  <p>However these remotes do exist and I can checkout each of them.  Many sites and people recommend that I run <code>git fetch --prune</code> to clean up missing references.  This does nothing because all of these remotes exist.</p>
  
  <h2>So I ask you, dear stack exchange;</h2>
  
  <ul>
  <li>Why can I delete one remote, but not many?</li>
  <li>Is my command correct?</li>
  </ul>
  
  <p>I think I'm missing something small.  Every time I research this, it seems like I'm doing this correctly, but I'm getting the above errors.</p>
  
  <ul>
  <li><a href="https://stackoverflow.com/questions/2003505/delete-a-git-branch-both-locally-and-remotely">Delete local and Remote Branches</a></li>
  <li><a href="https://gist.github.com/schacon/942899" rel="noreferrer">gist Delete Merged Remotes</a></li>
  </ul>