
There are three ways to list the remote branches associated with a Git repository: , and you consent to receive offers and opportunities from Career Karma by telephone, text message, and email. Get Your Coding Bootcamp Sponsored by Your EmployerĬareer Karma matches you with top tech bootcampsĪccess exclusive scholarships and prep courses.Education Stipends for Coding Bootcamps.Best Coding Bootcamp Scholarships and Grants.Ultimate Guide to Coding Bootcamp Loans.
GIT LIST BRANCHES BY CREATION DATE FREE
Best Free Bootcamps and Coding Training.Best Online Coding Bootcamps and Courses.The best overall strategy is to adopt a strategy that does not let this situation occur: give the individuals reviewing and completing PRs the permission to delete branches and encourage teams to squash and delete branches as they complete PRs. In that scenario, encourage the team to keep these important branches up-to-date to retain the value of the invested effort. The majority of old branches are likely abandoned work, but there's sometimes scenarios where partially completed work is waiting on some external dependency. Using a combination of these techniques we could easily reduce the amount of stale branches, and then provide the remaining list to the team to have them clean-up the dredges. It’s important to recognize this only includes the completed PRs, not the active or abandoned. This is roughly a 40% reduction, and I’ll take that for now. query "." –f $result.updateStatus)Īt first glance, this would remove about 50% of the remaining branches in our repository, leaving us with 10-20% recent branches and an additional 30-40% of branches without PRs. We can find the authors for the branches with the following PowerShell + Az DevOps CLI: $project = ""

Simply track down the branch authors and ask them to determine if they’re done with them. One approach to cleaning-up stale branches is the old fashion way: nagging. If we want to run this from a pipeline, we would have to grant the Build Service the same permissions. See my last post on ways to apply this policy programmatically. You’ll need the “ Force push (rewrite history, delete branches and tags)” permission to delete the branch. You can change the default setting by adding the appropriate user or group to the repository’s permissions and the existing branches will inherit. If you don’t have permission, the option isn’t available to you in the user-interface, and this creates a missed opportunity to remediate the issue when someone other than the author completes the PR. In Azure DevOps, the default permission settings set up the creator of the branch with the permission to delete it. One of the reasons branches don’t get deleted might be a permissions problem.

This also opens up the possibility of running these activities in a PowerShell script in an Azure Pipeline, as outlined in my previous post. I want to use the Azure DevOps CLI and REST APIs for this instead of git-centric commands because I want to be able to run the scripts from any computer against the latest version of the repository. What’s the best way to find which branches can be safely deleted? This post will explore some approaches to find and delete stale branches.Īs there are many different ways we can approach this, I’m going to start with the most generic concepts and build up to a more programmatic solution. If you have pull-requests, you likely have stale branches.
