Skip to content

Instantly share code, notes, and snippets.

@ba55ie
Last active August 26, 2026 10:22
Show Gist options
  • Select an option

  • Save ba55ie/7fa073d7b83568d7d30553500599c101 to your computer and use it in GitHub Desktop.

Select an option

Save ba55ie/7fa073d7b83568d7d30553500599c101 to your computer and use it in GitHub Desktop.
Git - Remove local branches that have been deleted on remote

Remove local branches

Remove local branches with the following commands.

  • yolo: deletes branches only if they have been fully merged into the upstream branch or current HEAD.
  • uber-yolo: deletes branches immediately, ignoring unmerged commits. ⚠️

How to

Add the following command to [alias] section in your global .gitconfig.

[alias]
  yolo = "!git fetch -p && git branch --format '%(refname:short) %(upstream:track)' | awk '$2 == \"[gone]\" {print $1}' | xargs -r git branch -d"
  uber-yolo = "!git fetch -p && git branch --format '%(refname:short) %(upstream:track)' | awk '$2 == \"[gone]\" {print $1}' | xargs -r git branch -D"

After saving you can use git yolo or git uber-yolo in your terminal of choice.

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