The first one is super simple – we want to remove all the references that are no longer on the remote. This can be done by executing our first clean up command:
git fetch --prune
|
Then we can remove any of the old branches that have already been merged. For that we can use the below command:
git --no-pager branch --merged | grep -Ev 'master|^\*' | xargs git branch -d
|
The first command gets a listing all the branches that have already been merged:
git --no-pager branch --merged
|
Next we need to remove the branches we want to keep. This is being done with a reverse regex
1 | grep |
(anything separated by the
1 | | |
is a or). The first one is the master branch we obviously don’t want to remove that. The next one is the branch starting with a
1 | * |
or in our case this is the branch you are currently on. Feel free to add any other branch names in here; for instance
1 | develop |
if you’re using the git flow workflow:
grep -Ev 'master|^\*'
|
Lastly we want to delete all the branches that are being printed out. This bit is simple – we can just use the
1 | git branch -d |
command and run it with
1 | xargs |
so we can pipe to the command. You may want to leave this last bit off on the first run so you can see what branches will be deleted as there is no
1 | --dry-run |
flag for this delete command:
xargs git branch -d
|
More reads
The Invisible Design Paradox: Why Beautiful Websites Don’t Always Succeed
There’s a persistent myth in digital strategy that equates aesthetic appeal with business success. The thinking goes that a beautiful website naturally translates into a successful one. The reality, however, is more nuanced.
Q3 Project updates
As a small yet busy web agency we often have little time to shout about what we are up to, and also work on secret projects we are unable to tell you about. Here’s a snapshot of what we’ve been working on…
[updated] Diagrams to live your life by
As part of our Practically Academy Sam shared a whole series of diagrams that help in the strategy work that he does, and beyond.



![[updated] Diagrams to live your life by](https://b2209735.smushcdn.com/2209735/wp-content/uploads/DiagramsTLYLB-Choice-vs-happiness-paradox-400x250.jpg?lossy=2&strip=1&webp=1)