github - Delete local Git branches after deleting them on the remote repo -


i want have local , remote repositories in sync in terms of branches.

after pull request review on github, merge , remove branch there (remote). how fetch information in local repository , git remove local version of branch well?

the quick way

git branch --merged | grep -v "\*" | xargs -n 1 git branch -d 

nb: if you're not on master, has potential delete branch. keep reading "better way".

make sure keep master

you can ensure master, or other branch matter, doesn't removed greping more. in case go:

git branch --merged | grep -v "\*" | grep -v "your_branch_to_keep" | xargs -n 1 git branch -d 

so if wanted keep master, develop , staging instance, go:

git branch --merged | grep -v "\*" | grep -ev "(\*|master|develop|staging)" | xargs -n 1 git branch -d 

make alias

since it's bit long, might want add alias .zshrc or .bashrc. mine called gbpurge (for git branches purge):

alias gbpurge='git branch --merged | grep -ev "(\*|master|develop|staging)" | xargs -n 1 git branch -d' 

then reload .bashrc or .zshrc:

. ~/.bashrc 

or

. ~/.zshrc 

Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

How to get multiresult with multicondition in Sql Server -