Skip to content

Commit

Permalink
ADDED: git branch clean feature
Browse files Browse the repository at this point in the history
  • Loading branch information
AleixMT committed Sep 8, 2023
1 parent 029101b commit ff053d6
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 0 deletions.
1 change: 1 addition & 0 deletions data/core/feature_arguments.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ audacity_arguments=("audacity")
AutoFirma_arguments=("auto_firma")
b_arguments=("b" "b_function")
bashcolors_arguments=("bash_colors" "colors" "colours")
bclean_arguments=("bclean" "branch_clean" "git_branch_clean")
blender_arguments=("blender" "blender_3d")
branch_arguments=("branch")
brasero_arguments=("brasero")
Expand Down
1 change: 1 addition & 0 deletions data/core/feature_keynames.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ axel
BFunction
b
bashcolors
bclean
blender
branch
brasero
Expand Down
8 changes: 8 additions & 0 deletions data/features/bclean/bclean.dat.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env bash
bclean_name="Function bclean"
bclean_description="Removes all local branches that do not have a remote counterpart in the git repository of the current directory"
bclean_version="1.0"
bclean_tags=("customDesktop" "bashFunctions" "gitFunctions")
bclean_systemcategories=("System" "Utility")

bclean_bashfunctions=("bclean.sh")
4 changes: 4 additions & 0 deletions data/features/bclean/bclean.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Git utility to remove all local branches that do not have remote counterpart.

Use the --interactive argument to perform the same clean but having the option to choose which branches are deleted.

12 changes: 12 additions & 0 deletions data/features/bclean/bclean.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/usr/bin/env bash

bclean()
{
if [ "$1" == "--interactive" ]; then
git branch --merged >/tmp/merged-branches && \ vi /tmp/merged-branches && xargs git branch -d </tmp/merged-branches
else
git fetch -p && for branch in $(git for-each-ref --format '%(refname) %(upstream:track)' refs/heads | awk '$2 == "[gone]" {sub("refs/heads/", "", $1); print $1}'); do git branch -D "${branch}"; done
fi
}

alias git-branch-clean="bclean"

0 comments on commit ff053d6

Please sign in to comment.