Blog Post

Deleting Stale Local Database Git Branches with SSMS–#SQLNewBlogger

,

I wrote a post recently about pruning branches in git. That’s part of the job, but the other part is removing local branches. This post looks at one way to do that in a semi-manual fashion.

This could be automated, but it took seconds, so I did a quick manual thing. I’ll work on an automated way, but since I do this rarely, manual is fine for me.

Another post for me that is simple and hopefully serves as an example for people trying to get blogging as #SQLNewBloggers. You can see all posts on Git as well.

Another post for me that is simple and hopefully serves as an example for people trying to get blogging as #SQLNewBloggers.

Getting a List of Branches to Delete

In the last post I showed how to get a list of branches with dry run. This was the image I showed of branches. If I re-run that without the dry run, the branches are removed.

2024-04-11 10_51_57-cmd

The output is similar, but either set of output works. Once we have a list of branches, what do we do? Let’s use SSMS to help.

SSMS Makes This Easy

If I highlight the results of my git prune, I can copy/paste those into SSMS. You can see below I’ve done this, and then held the ALT+Shift key to select a bunch of text in a box. This is all the text apart from the branch names.

2024-04-11 10_54_39-SQLQuery4.sql - not connected_ - Microsoft SQL Server Management Studio

Once I’ve done this, I can let go of those keys and type “git branch –d “, which will replace the text on every line. You can see this below.

2024-04-11 10_54_52-SQLQuery4.sql - not connected_ - Microsoft SQL Server Management Studio

This is a great technique, and while it works in VSCode and some other editors, I usually have SSMS open and it works very well here. I then select all this text, paste it back into the CMD window, accept the note that this is a multi-line paste, and all my deletes run.

2024-04-11 10_55_27-cmd

Voila, all remote branches deleted are removed from my local git install. A few of these were already removed manually as I experimented.

SQL New Blogger

As I mentioned in the previous post, version control skills (especially git) are core for most technology pros. DBA, developers, sysadmin, anyone working with modern software development or administration likely needs to know about version control.

This post was about 10 minutes. You could write this in 15 and showcase your tech skills to a future employer.

Original post (opens in new tab)
View comments in original post (opens in new tab)

Rate

You rated this post out of 5. Change rating

Share

Share

Rate

You rated this post out of 5. Change rating