DEV Community

Maks Yadvinskyy
Maks Yadvinskyy

Posted on

4 2

Git Holiday Cleanup 🌲

The year is almost over and the holidays are approaching, what a good time to say goodbye to your old stale branches. I know letting go of something is always hard, but don't sweat it. I'll teach you how to keep the things you need and remove purge the rest.

Step 1

Get a list of my local branches

git branch >> git_branches.txt
Enter fullscreen mode Exit fullscreen mode
Step 2

In the editor mark the branches that you want to keep

123-branch-to-remove
* master
* dev
* keep-branch
Enter fullscreen mode Exit fullscreen mode
Step 3

Run the command bellow to verify the branches you want gone

cat git_branches.txt | grep "^[^\*].*"
Enter fullscreen mode Exit fullscreen mode
Step 4

If they are all good then run the same command and feed it into git branch -D

cat git_branches.txt | grep "^[^\*].*" | xargs git branch -D
Enter fullscreen mode Exit fullscreen mode
Step 5

Enjoy the holidays, show this to your colleagues and be nice!

Top comments (2)

Collapse
 
jonmajorc profile image
Jon Major Condon

Awesome!! Could be CLI package 😃

Collapse
 
maks_yadvinskyy profile image
Maks Yadvinskyy

🤦‍♂️ Why didn't I think of that? You're a genius!

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Immerse yourself in a wealth of knowledge with this piece, supported by the inclusive DEV Community—every developer, no matter where they are in their journey, is invited to contribute to our collective wisdom.

A simple “thank you” goes a long way—express your gratitude below in the comments!

Gathering insights enriches our journey on DEV and fortifies our community ties. Did you find this article valuable? Taking a moment to thank the author can have a significant impact.

Okay