2

I am trying to do some remedial git clean-up work on a repository that was started a while back. When I run git branch -a I get the following output:

$ git branch -a
* master
staging
remotes/origin/master
remotes/origin/staging
remotes/pythonanywhere/master
remotes/pythonanywhere/staging
remotes/staging/staging

The remotes/staging/staging remote does not exist anymore. It does not show up in the list when running git remote -v.

This also seems to mean I cannot delete the remote.

get fetch -p, git remote prune staging also do not work.

Also the remote does not show up in the list of remotes when running git config --local -l

EDIT:

The suggested possible duplicate questions/answers did not work when trying to solve this issue. For some reason the remote was left as an orphan. See the accepted answer below for what worked.

Community
  • 1
  • 1
trejas
  • 991
  • 7
  • 17
  • Possible duplicate of [How to delete remotes/origin/{branch}?](https://stackoverflow.com/questions/4703200/how-to-delete-remotes-origin-branch) – marcusshep Aug 17 '17 at 19:38
  • Check the accepted answer for [How do I delete a Git branch both locally and remotely?](https://stackoverflow.com/a/2003515/5395709) – M3talM0nk3y Aug 17 '17 at 19:42
  • Possible duplicate of [Remove local branches no longer on remote](https://stackoverflow.com/questions/7726949/remove-local-branches-no-longer-on-remote) – mintychai Aug 17 '17 at 19:42
  • Thanks for pointing to these other answers. I perused them all before deciding to ask my own version. Each of those answers contained steps that I tried first, but did not work. Thus the new question, which was just answered in the comments below. – trejas Aug 17 '17 at 20:05
  • If none of the `git` commands seems to do the tricks you might have to get your hands dirty. Make a complete backup of your git repository and working folder to be sure, then venture with a flashlight into the `.git/refs/remotes` folder, then remove the remote folder you no longer want there. Afterwards, do a `git fsck` to be sure you didn't mess something else up. Also check the `.git/config` file for lingering traces of the remote. – Lasse V. Karlsen Aug 17 '17 at 21:13
  • Note that normally such remotes would have been removed with `git remote remove` in the first place, which would have taken care of the problem—presumably someone removed the remote "by hand" and failed to remove the corresponding remote-tracking branches "by hand". The add-then-remove trick seems like the simplest cleanup though! – torek Aug 18 '17 at 00:39

2 Answers2

3

Is this the same question you have?

git remote prune origin prunes tracking branches not on the remote.

mintychai
  • 281
  • 3
  • 10
  • Thanks. This seems like it should work in theory, but I did try this already (see the bottom part of my question). No dice. – trejas Aug 17 '17 at 20:07
1

As per the suggestion in the comments, this is what works:

git remote add <remote name> <url> 
git remote remove <remote name>

Seemed to clear out some dangling reference to the orphaned remote.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
wmorrell
  • 4,988
  • 4
  • 27
  • 37