Skip to content

Instantly share code, notes, and snippets.

@ytlm
Last active April 15, 2019 06:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ytlm/7a06331a181eb8d494d09f3d3d7244da to your computer and use it in GitHub Desktop.
Save ytlm/7a06331a181eb8d494d09f3d3d7244da to your computer and use it in GitHub Desktop.
同步删除已经在远程被删除的本地分支
git fetch -p
git remote prune origin
# 删除所有已经merge到master上的分支
git branch --merged master | grep -v '^\*\| master' | xargs -n 1 git branch -d
# 查找所有远程分支不存在的本地分支,然后再用git branch -d进行删除
for b in $(git branch -vv | grep -v origin | awk '{print $1}'); do
flag=0
for ob in $(git branch -r | awk '{print $1}' | awk -F '/' '{print $2}'); do
if [ "$b" == "$ob" ]; then
flag=1
break
fi
done
if [ $flag == 0 ];then
echo $b
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment