Delete local Git branches after deleting them on the remote repo

前端 未结 12 1964
死守一世寂寞
死守一世寂寞 2020-11-30 16:26

I want to have my local and remote repositories always in sync in terms of branches.

After a Pull Request review on GitHub, I merge and remove my branch there (remot

12条回答
  •  南方客
    南方客 (楼主)
    2020-11-30 17:10

    I had the same question and I could solve it with a simple command line:

    git branch -d $(git branch --merged | grep -v "master")

    First of all, do a git pull origin to make sure it will work fine.

    The subshell first returns all branches that were merged to your current branch (make sure you have master branch checked out!!!), except for master which can be on the list if you don't use grep -v. Then, all merged branches will be simply removed from your local repo by git branch -d

提交回复
热议问题