Created
March 23, 2021 01:42
-
-
Save leeopop/c7341beb8e5bb94cdd543e770977ead6 to your computer and use it in GitHub Desktop.
Remove untracked branches on git
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -o noglob | |
git remote update --prune | |
raw_input=$(git branch -vv) | |
while read -r line; do | |
branch_line=$(echo "$line" | sed s/*//g) | |
branch_line=$(echo $branch_line) | |
branch_name=${branch_line%% *} | |
if [[ $branch_line =~ "[origin/" ]] | |
then | |
has_origin=true | |
else | |
has_origin=false | |
fi | |
if [[ $branch_line =~ ": gone" ]] | |
then | |
has_gone=true | |
else | |
has_gone=false | |
fi | |
if [ $has_gone = true ] || [ $has_origin = false ] | |
then | |
echo "Removing branch $branch_name ..." | |
git branch -d $branch_name | |
fi | |
done <<< "$raw_input" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -o noglob | |
git remote update --prune | |
raw_input=$(git branch -vv) | |
while read -r line; do | |
branch_line=$(echo "$line" | sed s/*//g) | |
branch_line=$(echo $branch_line) | |
branch_name=${branch_line%% *} | |
if [[ $branch_line =~ "[origin/" ]] | |
then | |
has_origin=true | |
else | |
has_origin=false | |
fi | |
if [[ $branch_line =~ ": gone" ]] | |
then | |
has_gone=true | |
else | |
has_gone=false | |
fi | |
if [ $has_gone = true ] || [ $has_origin = false ] | |
then | |
echo "Removing branch $branch_name ..." | |
git branch -D $branch_name | |
fi | |
done <<< "$raw_input" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
git remote update --prune; git branch -vv | % { | |
$branch_line = $_.toString().Replace("*","").Trim(); | |
$branch_name = $branch_line.Replace("*","").Trim().Split(" ")[0]; | |
$has_origin = $branch_line.Contains("[origin/"); | |
$has_gone = $branch_line.Contains(": gone"); | |
if ($has_gone -or -not $has_origin) { | |
git branch -D $branch_name; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
git remote update --prune; git branch -vv | % { | |
$branch_line = $_.toString().Replace("*","").Trim(); | |
$branch_name = $branch_line.Replace("*","").Trim().Split(" ")[0]; | |
$has_origin = $branch_line.Contains("[origin/"); | |
$has_gone = $branch_line.Contains(": gone"); | |
if ($has_gone -or -not $has_origin) { | |
git branch -d $branch_name; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment