删除远程分支的尝试失败 :
$ git branch -d remotes/origin/bugfix
error: branch 'remotes/origin/bugfix' not found.
$ git branch -d origin/bugfix
error: branch 'origin/bugfix' not found.
$ git branch -rd origin/bugfix
Deleted remote branch origin/bugfix (was 2a14ef7).
$ git push
Everything up-to-date
$ git pull
From github.com:gituser/gitproject
* [new branch] bugfix -> origin/bugfix
Already up-to-date.
我如何正确删除本地和远程的远程/原产/bugfix分支?
答案是好的, 但是, 如果您有一大堆分支, 逐个删除本地和远程的分支, 将会是一个无聊的任务 。 您可以使用此脚本将这些任务自动化 。
branch_not_delete=( "master" "develop" "our-branch-1" "our-branch-2")
for branch in `git branch -a | grep remotes | grep -v HEAD | grep -v master`; do
# Delete prefix remotes/origin/ from branch name
branch_name="$(awk '{gsub("remotes/origin/", "");print}' <<< $branch)"
if ! [[ " ${branch_not_delete[*]} " == *" $branch_name "* ]]; then
# Delete branch remotly and locally
git push origin :$branch_name
fi
done
列出您不想删除的在遥控器分支上的循环的分支, 如果它们不在我们的“ 保存列表” 中, 则将其删除 。
来源: 立即删除 Git 分支