Skip to content

Instantly share code, notes, and snippets.

@nunosilva800
Last active July 6, 2018 13:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nunosilva800/840a400f7bc94c2e984b to your computer and use it in GitHub Desktop.
Save nunosilva800/840a400f7bc94c2e984b to your computer and use it in GitHub Desktop.
cleaning git repo
# To delete all branches that are already merged into the currently checked out branch:
git branch --merged | grep -v "\*" | xargs -n 1 git branch -d
@nunosilva800
Copy link
Author

or as a git alias:

[alias]
        dm = "!git branch --merged | grep -v \"\\*\" | xargs -n 1 git branch -d"

@nunosilva800
Copy link
Author

use flag -r to force acting on remote-tracking branches

@nunosilva800
Copy link
Author

others:

  • git branch -r to list old tracking branches that have been left in your local repo.
  • git remote prune origin to delete the local tracking branches that don’t exist on origin anymore
  • git ls-remote --heads origin list branches on remote origin
  • git push origin --delete old_branch delete old branch on origin

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