Solution
To delete all local Git branches except for the develop
branch, you can use the following steps:
git branch | grep -v "develop" | xargs git branch -d
If you also want to include remote-tracking branches, use:
git branch -r | grep -v "develop" | sed 's/origin\///' | xargs -I {} git branch -d {}
This will:
git branch
.develop
branch from the list using grep -v "develop"
.xargs git branch -d
.Note: The -d
flag will only delete branches that have been fully merged. If you have unmerged branches and want to force delete them, use the -D
flag instead of -d
. Be cautious with this as it will delete branches regardless of their merge status.