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.
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?
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.
+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
.
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.
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
Most helpful comment
With the addition of
hub pr list
in 2.3.0, we can now do:Given a PR number, this will return the branch name.
So altogether, it would be possible to do this: