Prune Dead Branches From Your Remotes
This is great if you've got remotes that are downstream or you treat as backups.
Pushing new branches to a remote is pretty simple, but deleting remote branches isn't as easy.
Place this in your ~/.bashrc:
function prune-remote () {
for branch in `git remote show ${1} | grep tracked | awk '{print $1}'`;
do
isLocal=`git branch | grep ${branch}`;
if [ -z "$isLocal" ]; then
git push ${1} :${branch};
fi;
done
}
And then in your ~/.gitconfig, you can define a new alias, prune-remote
or whatever you want to call it:
[alias]
prune-remote = !bash -ic 'prune-remote $@' -
To use it, it's very simple. Suppose you have a remote named backup
.
All you'd need to run then is: git prune-remote backup
.
Check out my gist for it as well.
Written by Daniel Miladinov
Related protips
1 Response
If you want to only remove remotes that have been merged into master, you can use git-sweep or git-branch-delete-orphans.
over 1 year ago
·
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Git
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#