How do you remove an invalid remote branch reference from Git?

前端 未结 11 2145
攒了一身酷
攒了一身酷 2020-11-28 16:43

In my current repo I have the following output:

$ git branch -a
* master
  remotes/origin/master
  remotes/public/master

I want to delete <

相关标签:
11条回答
  • 2020-11-28 17:37

    In my case I was trying to delete entries that were saved in .git/packed-refs. You can edit this plain text file and delete entries from it that git br -D doesn't know how to touch (At least in ver 1.7.9.5).

    I found this solution here: https://stackoverflow.com/a/11050880/1695680

    0 讨论(0)
  • 2020-11-28 17:39
    git push origin --delete <branch name>
    

    Referenced from: http://www.gitguys.com/topics/adding-and-removing-remote-branches/

    0 讨论(0)
  • 2020-11-28 17:40

    I didn't know about git branch -rd, so the way I have solved issues like this for myself is to treat my repo as a remote repo and do a remote delete. git push . :refs/remotes/public/master. If the other ways don't work and you have some weird reference you want to get rid of, this raw way is surefire. It gives you the exact precision to remove (or create!) any kind of reference.

    0 讨论(0)
  • 2020-11-28 17:41

    Only slightly related, but still might be helpful in the same situation as we had - we use a network file share for our remote repository. Last week things were working, this week we were getting the error "Remote origin did not advertise Ref for branch refs/heads/master. This Ref may not exist in the remote or may be hidden by permission settings"

    But we believed nothing had been done to corrupt things. The NFS does snapshots so I reviewed each "previous version" and saw that three days ago, the size in MB of the repository had gone from 282MB to 33MB, and about 1,403 new files and 300 folders now existed. I queried my co-workers and one had tried to do a push that day - then cancelled it.

    I used the NFS "Restore" functionality to restore it to just before that date and now everythings working fine again. I did try the prune previously, didnt seem to help. Maybe the harsher cleanups would have worked.

    Hope this might help someone else one day!

    Jay

    0 讨论(0)
  • 2020-11-28 17:43

    The accepted answer didn't work for me when the ref was packed. This does however:

    $ git remote add public http://anything.com/bogus.git
    $ git remote rm public
    
    0 讨论(0)
提交回复
热议问题