Skip to content

Instantly share code, notes, and snippets.

@msoler8785
Last active September 12, 2022 17:42
Show Gist options
  • Save msoler8785/9eb134a9964b9fe62985c6cd13b7cbb9 to your computer and use it in GitHub Desktop.
Save msoler8785/9eb134a9964b9fe62985c6cd13b7cbb9 to your computer and use it in GitHub Desktop.
Bulk Delete Git Tags

Bulk delete tags from a repo using PowerShell.

Run these commands from the root of your repo.

Function Delete-TagPattern 
{
    Param(
        [Parameter(
            Mandatory, 
            HelpMessage="Enter a pattern for the tags you want to match E.g. `"1.0.0.*`""
        )]
        [string] $TagPattern
    )
    
    $tags = git tag -l $TagPattern

    if (-not $tags) 
    { 
        Write-Host "No tags match the specified pattern of $TagPattern";
        return;
    }
    
    Write-Host;
    # view the results    
    $tags

    $prompt = Read-Host -Prompt "Would you like to delete these tags (y or n)?"

    if ($prompt -eq "y") 
    {
        $tags | ForEach-Object { git push --delete origin $_; git tag -d $_; }
    }
}

Delete-TagPattern
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment