At my work, I build up a large collection of branches in my git repository over time. Eventually the large number of branches gets overwhelming and requires some maintenance to make the project more manageable (AKA less cluttered). Cleaning up the local and remote branches tends to follow this two step process:
- Delete local branch: git branch -d name_of_branch
- Delete remote branch: git push origin :name_of_branch
After doing some research, I did not find any quick and dirty way to delete both the local and remote branches with one simple command in git on a Mac. However, I did eventually discover a Ruby script named git-branch-delete that someone1 had written which does nicely perform this task.
Installation for OS X
- Download the file git-branch-delete
- Extract the file git-branch-delete from the compressed tarball
- Copy the file git-branch-delete to /usr/local/bin
- Set the proper permissions: chmod 755 /usr/local/bin/git-branch-delete
Usage
Once this has been set up, open up a new Terminal session and delete old git branches from the command line using the following command: git branch-delete <branch-name>
Reference
Edenwaith git-branch-delete Gist : https://gist.github.com/edenwaith/8118506
Footnote
1) Original source : https://github.com/scottwb/dotfiles/blob/master/bin/git-branch-delete