When working on a project, the number of branches tend to increase linearly with the work being done. Personally, I don’t like to have all this clutter in my branch list. When I look at the branches, I just want to see the active stuff. A common way to deal with this problem in git is to archive branches. Git doesn’t natively supported the concept of an archived branch, but the usual way to emulate this is by creating a tag called
archive/<branchname> and removing the branch after that. If you have many branches, it is convenient to be able to do this automatically and interactively. I wrote a little python script to make the whole thing take little time and effort.
Here is an example of the script in action.
$ python archive_merged_branches.py Archive branch DR-010559? [y/n]y Archive branch DR-010579? [y/n]y Archive branch DR-010580? [y/n]y Archive branch DR-010586? [y/n]y Archive branch DR-010707? [y/n]y Archive branch chiel/doc? [y/n]n Created archive tags: DR-010559 DR-010579 DR-010580 DR-010586 DR-010707 Push archive tags to remote? [y/n]y To <remote host> * [new tag] archive/DR-010559 -> archive/DR-010559 To <remote host> * [new tag] archive/DR-010579 -> archive/DR-010579 To <remote host> * [new tag] archive/DR-010580 -> archive/DR-010580 To <remote host> * [new tag] archive/DR-010586 -> archive/DR-010586 To <remote host> * [new tag] archive/DR-010707 -> archive/DR-010707 Corresponding remote branches: origin/DR-010559 origin/DR-010579 origin/DR-010580 origin/DR-010586 origin/DR-010707 Delete remote branches? [y/n]y To <remote host> - [deleted] DR-010559 error: unable to delete 'DR-010579': remote ref does not exist error: failed to push some refs to <remote host> To <remote host> - [deleted] DR-010580 To <remote host> - [deleted] DR-010586 To <remote host> - [deleted] DR-010707 Corresponding local branches: DR-010559 DR-010579 DR-010580 DR-010586 DR-010707 Delete local branches? [y/n]y Deleted branch DR-010559 (was a3cdf9b). Deleted branch DR-010579 (was 398ca49). Deleted branch DR-010580 (was b8107c6). Deleted branch DR-010586 (was 918a0c5). Deleted branch DR-010707 (was 898fe26).