Wake Me Up When September Ends.

A wanderer capable of grasping the beauty of the grass, with a heart full of ancient charm, and a fondness for playful wit. Those who understand my words are knowledgeable individuals; those who decipher my code truly comprehend the essence. I am a wandering code swordsman, carrying my skills and riding freely through the digital world.

Git 批量删除本地以及远程分支

1. 查看所有本地分支:

git branch

2. 删除本地分支:

git branch -D branch_name


3. 查看所有远程分支:

$ git branch -r

4. 删除远程分支:

git push origin --delete branch_name


git branch | grep -v "main" | xargs git branch -D



git branch -r | grep -v "main" | sed 's/origin\//:/' |  xargs git push

main为要保留的分支名称,可以根据需要进行修改。最后一个命令中的sed命令是将远程分支名中的origin/替换为:/,因为git push命令中需要使用的远程分支名不包含origin/