bag.git.delete_old_branches module

A solution to the problem of cleaning old git branches.

A command that removes git branches that have been merged onto the current branch.

Usage:

# Try this to see the supported arguments:
delete_old_branches --help

# Ensure you are in the branch "master" before starting.
# Test first, by printing the names of the branches that would be deleted:
delete_old_branches -l -r origin -y 0 --dry

# If you agree, run the command again without --dry:
delete_old_branches -l -r origin -y 0

If you don’t like the 2 steps, just omit -y and the command will confirm each branch with you before deleting it.

The zero in the above example is a number of days since the branch was merged into the branch you are in.

Don’t forget to do a “git fetch –all –prune” on other machines after deleting remote branches. Other machines may still have obsolete tracking branches (see them with “git branch -a”).

class bag.git.delete_old_branches.Branch(name, remote='')[source]

Bases: object

delete()[source]
is_older_than_days(age)[source]
Return type

bool

merge_date

Return the date when the specified branch was merged.

…into the current branch. On the console, you can try this command:

git show –pretty=format:”%Cgreen%ci %Cblue%cr%Creset” BRANCH | head -n 1

bag.git.delete_old_branches.delete_old_branches(days, dry=False, locally=False, remote=None, y=False, ignore=['develop', 'master'])[source]
bag.git.delete_old_branches.merged_branches(remote=None, ignore=['develop', 'master'])[source]

Sequence of branches that have been merged onto the current branch.