Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove remote merged branches command #79

Closed
haacked opened this issue Feb 11, 2013 · 15 comments
Closed

Remove remote merged branches command #79

haacked opened this issue Feb 11, 2013 · 15 comments
Assignees
Milestone

Comments

@haacked
Copy link
Contributor

haacked commented Feb 11, 2013

So we (GHfW) team have a PowerShell script that will list all remote branches that are already merged into a specified branch (it defaults to origin/master if no branch is supplied) and offer to delete them for you.

I'd love to clean it up and add it as a command to GitUtils.ps1. Would you be interested in such a thing as part of Posh-Git?

@dahlbyk
Copy link
Owner

dahlbyk commented Feb 11, 2013

Sure!

I've actually had the following in my own profile for some time and was considering adding it to posh-git...

function Delete-MergedBranches ($Commit = 'HEAD', [switch]$Force) {
    git branch --merged $Commit |
        ? { $_ -notmatch '(^\*)|(^. master$)' } |
        % { git branch $(if($Force) { '-D' } else { "-d" }) $_.Substring(2) }
}

@haacked
Copy link
Contributor Author

haacked commented Feb 11, 2013

I have one that works without PS in pretty much any shell. :) But it doesn't prompt you. That's one thing ours does that's nice. It lists them out and prompts you.

@dahlbyk
Copy link
Owner

dahlbyk commented Feb 11, 2013

Prompts to force delete, you mean?

Out of curiosity, have you tried Update-AllBranches?

@JayBazuzi
Copy link
Collaborator

Are you wishing for a -Confirm parameter?

@haacked
Copy link
Contributor Author

haacked commented Feb 11, 2013

@dahlbyk I have not. It just prompts you before it chooses to delete the remote branches.

clean-merged-branches-prompt

^^^ Here's a screenshot. Unfortunately I only have one branch that needs to be cleaned so it doesn't show you how it might normally look. But you get the idea. We show you the list. We prompt you to delete.

@dahlbyk
Copy link
Owner

dahlbyk commented Feb 12, 2013

If the branches have already been merged, I'm curious why you default to requesting confirmation? I'd tend to flip it around and offer a -WhatIf parameter to see what would be removed if you're not sure. Perhaps more PowerShell-y?

@haacked
Copy link
Contributor Author

haacked commented Feb 12, 2013

Because I'm paranoid. :) A -WhatIf seems reasonable.

@dahlbyk
Copy link
Owner

dahlbyk commented Feb 12, 2013

Git's pretty good about only doing things that are safe... I figure -Force to override warnings against potentially destructive changes, -WhatIf to see potentially safe changes.

@JayBazuzi
Copy link
Collaborator

And -Confirm.

-J on a phone.
On Feb 12, 2013 1:47 PM, "Keith Dahlby" notifications@github.com wrote:

Git's pretty good about only doing things that are safe... I figure -Forceto override warnings against potentially destructive changes,
-WhatIf to see potentially safe changes.


Reply to this email directly or view it on GitHubhttps://github.com//issues/79#issuecomment-13460964.

@vorou
Copy link
Contributor

vorou commented Jan 15, 2014

What's the status of the issue?

@dahlbyk
Copy link
Owner

dahlbyk commented Jan 15, 2014

What's the status of the issue?

@haacked do you still have your function handy?

@sclarson
Copy link

Would you want the default branch to always be master, or the current branch?

@dahlbyk
Copy link
Owner

dahlbyk commented Sep 29, 2014

Defaulting to HEAD seems reasonable.

@bcdady
Copy link

bcdady commented Apr 26, 2015

Have @dahlbyk or @JayBazuzi reviewed the pull request (#159) by @tkirill ?
Unless there's an issue with the proposed functions / enhancements, when might we be able to see this committed / released?

@tkirill
Copy link

tkirill commented Apr 27, 2015

@bcdady Glad to see there is someone else who interested in this functionality! I've already thought no one need this.

These cmdlets are fully tested at this moment. We use them in our team daily and never had a single problem or crash.

@dahlbyk dahlbyk added this to the Ideas milestone Feb 6, 2017
rkeithhill added a commit that referenced this issue Feb 19, 2019
Not sure if this command should require confirmation by default.

Perhaps we also need a Remove-GitBranch command which would need
confirmation.
@rkeithhill rkeithhill self-assigned this Feb 19, 2019
rkeithhill added a commit that referenced this issue Feb 20, 2019
Not sure if this command should require confirmation by default.

Perhaps we also need a Remove-GitBranch command which would need
confirmation.
rkeithhill added a commit that referenced this issue Feb 24, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants