Skip to content

Instantly share code, notes, and snippets.

@erayalakese
Last active August 22, 2018 13:44
Show Gist options
  • Save erayalakese/b9d611d8ae1b1420a206928d54d0c1e8 to your computer and use it in GitHub Desktop.
Save erayalakese/b9d611d8ae1b1420a206928d54d0c1e8 to your computer and use it in GitHub Desktop.
Git Repository House Keeping

Remove all merged (into master) remote branches First run with --dry-run and check if everything is OK

git branch -r --merged origin/master | 
grep origin | 
grep -v '>' | 
grep -v master | 
xargs -L1 | 
cut -d"/" -f2- | 
xargs git push origin --dry-run --delete

Remove tracking branches if the remote branch is deleted

git remote prune origin

Remove all local branches if remote upstreams are removed

git branch -vv | grep 'origin/.*: gone]' | awk '{print $1}' | xargs git branch -d 
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment