DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»

DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’» is a community of 963,274 amazing developers

We're a place where coders share, stay up-to-date and grow their careers.

Create account Log in
Maksym Yadvinskyy
Maksym Yadvinskyy

Posted on

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!

Latest comments (2)

Collapse
 
jonmajorc profile image
Jon Major Condon

Awesome!! Could be CLI package πŸ˜ƒ

Collapse
 
maks_yadvinskyy profile image
Maksym Yadvinskyy Author

πŸ€¦β€β™‚οΈ Why didn't I think of that? You're a genius!

πŸ‘‹ Hey, my name is Noah and I’m the one who set up this ad. My job is to get you to join DEV, so if you fancy doing me a favor, I’d love for you to create an account.

If you found DEV from searching around, here are a couple of our most popular articles on DEV: