Skip to content

Instantly share code, notes, and snippets.

@unrevised6419
Last active November 4, 2021 09:18
Show Gist options
  • Select an option

  • Save unrevised6419/e184f30a3013857bf3032b70fd4b0aa9 to your computer and use it in GitHub Desktop.

Select an option

Save unrevised6419/e184f30a3013857bf3032b70fd4b0aa9 to your computer and use it in GitHub Desktop.
Git alias to remove all local branches that are gone on remote

Create alias manually in ~/.gitconfig file (recommened):

[alias]
	gone = "!f() { git fetch --all --prune; git branch -vv | awk '/: gone]/{print $1}' | xargs git branch -D; }; f"

Create alias (problematic):

git config --global alias.gone '!f() { git fetch --all --prune; git branch -vv | awk "/: gone]/{print $1}" | xargs git branch -D; }; f'

Usage:

git gone

Blog post:

https://dev.to/iamandrewluca/remove-gone-git-branches-36eh

@unrevised6419
Copy link
Copy Markdown
Author

Yes, creating this alias from command line is a little bit problematic because involves a lot of quotes 🙂

Easier would be to open ~/.gitconfig file in a text editor and add it manually

[alias]
	gone = "!f() { git fetch --all --prune; git branch -vv | awk '/: gone]/{print $1}' | xargs git branch -D; }; f"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment