Search code examples
gitmsysgitgit-extensions

Removing tracking references to remote that no longer exists


My remote was named BitBucket and I decided to rename it origin, so I deleted BitBucket and created origin with the same URL as BitBucket.

Now I seem to have tracking references for both origin and the now-deleted BitBucket. How do I get rid of the tracking references for BitBucket?

I've seen lots of references online to pruning but that seems to only work with a remote that still exists. How do I clean out references to branches in a remote that no longer exists?


Solution

  • If you rename/delete a remote reference, all remote tracking branches would be renamed or deleted too.

    So try and rename origin to BitBucket (to get back to the initial state):

    git remote rename origin BitBucket
    git fetch BitBucket
    

    (That should make sure you have only the remote 'BitBucket' tracking branches)

    Then rename the remote BitBucket into origin:

    git remote rename BitBucket origin
    

    And check if the remote tracking branches remotes/BitBucket/xxx have been renamed in remotes/origin/xxx.