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

[Feature Request] Allow merge to delete branches locally and remotely #1587

Open
lunks opened this issue Oct 10, 2017 · 5 comments
Open

[Feature Request] Allow merge to delete branches locally and remotely #1587

lunks opened this issue Oct 10, 2017 · 5 comments
Labels

Comments

@lunks
Copy link

lunks commented Oct 10, 2017

On my current flow it'd be ideal if I had the option of deleting both remote and local branches when I merge a PR.

I could script it, but the way hub works when merging is using an URL which I don't have the branch name at hand.

@mislav mislav added the feature label Oct 16, 2017
@mislav
Copy link
Owner

mislav commented Oct 16, 2017

Thanks for suggesting! It's a good idea. Let me think about this for a while and see if we can incorporate this into the roadmap. Do you imagine this to be an extra, optional flag to git merge command?

@lunks
Copy link
Author

lunks commented Oct 16, 2017

This could be a flag for git merge and I should be able to configure it as default in my .gitconfig file.

If we mimic how git branch --delete works we should be able to make sure we don't delete the local branch in case I forgot to send changes from my local environment upstream.

@vfonic
Copy link

vfonic commented Oct 30, 2017

+1

@lunks how do you merge PRs from the CLI at the moment? Is there any way to merge PRs from CLI/hub that creates the same message like the one when doing merge through web UI. For example:

Merge pull request #123 from vfonic/ui-fixes

UI Fixes

Ah, seems like this does the job git merge https://github.com/vfonic/repo/pull/123
Although I couldn't find anything when running git help merge.

@OliverJAsh
Copy link
Contributor

If hub provided a command to get the branch name for a given pull request URL, we might be able to build this easily in user land.

@OliverJAsh
Copy link
Contributor

If hub provided a command to get the branch name for a given pull request URL, we might be able to build this easily in user land.

With the addition of hub pr list in 2.3.0, we can now do:

hub pr list -f "%i %H%n" | grep $PR_NUMBER | cut -d ' ' -f 2

Given a PR number, this will return the branch name.

So altogether, it would be possible to do this:

# Store branch name before it gets merged
BRANCH=`hub pr list -f "%U %H%n" | grep $PR_NUMBER_OR_URL | cut -d ' ' -f 2`

# Merge to base (assumed to be master) and push
git checkout master
hub merge $PR_URL
git push

# Delete local/remote branch
git branch -D $BRANCH
git push origin :$BRANCH

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants