Can't delete branch even though it shows up in git branch

git branch -r --merged | grep 123

OUTPUT

origin/feature/123-some-feature

git branch -r --merged | grep 123 | xargs git branch -d

OUTPUT error: branch 'origin/feature/123-some-feature' not found.

Why can't I delete this remote branch?

EDIT: Sorry, should have been more clear on my initial post (I was in a meeting when I wrote this). I don't have any of these branches locally and I'm trying to do a cleanup of the remote repository to delete all merged branches (I'm testing it by filtering to just '123' for now).

I want to get a filtered (via grep) list of the remote branches that have been merged so I can review them locally to be sure I'm not going to delete any branches I want to keep.

Then I want to execute it again with | xargs git branch -d | xargs git branch -d to actually remove those branches from the remote repository.

I think this would be what I want based on the posted answer and one of the comments?

git branch -r --merged | grep 123 | xargs git push origin --delete


You can't delete it because it's a remote branch. It exists in the remote repository, not in your local repository. If you want to delete it on the remote, you can:

git push --delete origin feature/123-some-feature

But understand that this will affect the availability of the branch on the remote repository.


You shouldn't use git branch -r to delete remote branch.
Use git push origin :your/branch/name (be sure you entered colon : before branchname)

链接地址: http://www.djcxy.com/p/26010.html

上一篇: Git远程覆盖导致两个断开连接的历史记录

下一篇: 即使它出现在git分支中,也不能删除分支