Last active
May 28, 2021 13:53
-
-
Save dee-me-tree-or-love/ffc27e1c6e5621f837283afb2ce5852c to your computer and use it in GitHub Desktop.
Check the active branches on remote, clean up the local branches that are no longer existing on remote
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/sh | |
| ################################################ | |
| # cleanup gone remote branches from local list # | |
| ################################################ | |
| git fetch -pP \ # fetch and prune gone remotes and remote tags | |
| && git branch -vv \ # display information about all branches | |
| | grep "\: gone\]" \ # find all the branches with "gone" remotes | |
| | awk '{print $1}' \ # get the branch names | |
| | xargs -i{} git branch -D {} # delete the local branches that are gone on remote | |
| ################## | |
| # as a one liner # | |
| ################## | |
| # ~ | |
| # $ git fetch -pP && git branch -vv | grep "\: gone\]" | awk '{print $1}' | xargs -i{} git branch -D {} | |
| # ~ | |
| ################## | |
| # as a git alias # | |
| ################## | |
| # ~ | |
| # $ git config --global alias.synclocalbranches \ | |
| # '!f() { git fetch -pP && git branch -vv | grep "\: gone\]" | awk "{print $1}" | xargs -i{} git branch -D {}; }; f' | |
| # ~ | |
| # This alias can now be run with | |
| # ~ | |
| # $ git synclocalbranches | |
| # ~ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment