LMSouq
general-dev AI Answered

Delete all local Git branches

LO
Louth
1 month ago
3 views
Problem Description
I follow a development process where I create a new local branch for every new feature or story card. When finished I merge the branch into *master* and then push. What tends to happen over time due to a combination of laziness or forgetfulness, is that I end up with a large list of local branches, some of which (such as spikes) may not have been merged. I know how to list all my local branches and I know how to remove a single branch but I was wondering if there was a Git command that allows me to delete all my local branches? Below is the output of the `git branch --merged` command. ```lang-none cd ~/projects/application git branch --merged ``` Output: ```lang-none STORY-123-Short-Description STORY-456-Another-Description STORY-789-Blah-Blah * master ``` All attempts to delete branches listed with `grep -v \*` (as per the answers below) result in errors: ```lang-none error: branch 'STORY-123-Short-Description' not found. error: branch 'STORY-456-Another-Description' not found. error: branch 'STORY-789-Blah-Blah' not found. ``` I'm using: * Git 1.7.4.1 * [Ubuntu 10.04][1] (Lucid Lynx) * [GNU][2] Bash, version 4.1.5(1)-release * GNU [grep][3] 2.5.4 [1]: https://en.wikipedia.org/wiki/Ubuntu_version_history#Ubuntu_10.04_LTS_.28Lucid_Lynx.29 [2]: https://en.wikipedia.org/wiki/GNU [3]: https://en.wikipedia.org/wiki/Grep

AI-Generated Solution

Powered by LMSouq AI · GPT-4.1-mini

✓ Solution Ready
Analyzing problem and generating solution…
Was this solution helpful?
Back to Knowledge Base