I have a bash alias to delete all the git branches which were also deleted on the remote Delete local Git branches after deleting them on the remote repo.
This is the command:
alias gbpurge="git checkout main; git pull; git fetch --all -p; git branch -vv | grep gone | awk '{ print $1 }' | xargs -n 1 git branch -d"
The output of git branch -vv | grep gone
is:
small-fixes dc454c7 [origin/small-fixes: gone] Removed superfluous tailwind class
style-elements 2103b56 [origin/style-elements: gone] Added design elements (background images etc.)
When I copy paste the content between the ' marks to the console this command works as expected and prints:
error: The branch 'small-fixes' is not fully merged.
If you are sure you want to delete it, run 'git branch -D small-fixes'.
error: The branch 'style-elements' is not fully merged.
If you are sure you want to delete it, run 'git branch -D style-elements'.
(These errors are expected here and not a problem)
however when I use the alias it prints:
error: The branch 'small-fixes' is not fully merged.
If you are sure you want to delete it, run 'git branch -D small-fixes'.
error: branch 'dc454c7' not found.
error: branch '[origin/small-fixes:' not found.
error: branch 'gone]' not found.
error: branch 'Removed' not found.
error: branch 'superflous' not found.
error: branch 'tailwind' not found.
error: branch 'class' not found.
error: The branch 'style-elements' is not fully merged.
If you are sure you want to delete it, run 'git branch -D style-elements'.
error: branch '2103b56' not found.
error: branch '[origin/style-elements:' not found.
error: branch 'gone]' not found.
error: branch 'Added' not found.
error: branch 'design' not found.
error: branch 'elements' not found.
error: branch '(background' not found.
error: branch 'images' not found.
error: branch 'etc.)' not found.
Why is it forwarding the commit message words as branch names in the alias?
Edit - changed outside quotes to double quotes and inside quotes aroudn $1 to single quotes