Delete a closed pull request from GitHub

GithubPull Request

Github Problem Overview


I accidentally made a wrong pull request and ended up closing the request myself. It's in a closed state right now but it's accessible via direct URL and showing on my activity bar.

Is there any way to delete a pull request completely so it's no longer accessible via URL or shows up on your activity history?

Github Solutions


Solution 1 - Github

There is no way you can delete a pull request yourself -- you and the repo owner (and all users with push access to it) can close it, but it will remain in the log. This is part of the philosophy of not denying/hiding what happened during development.

However, if there are critical reasons for deleting it (this is mainly violation of Github Terms of Service), Github support staff will delete it for you.

Whether or not they are willing to delete your PR for you is something you can easily ask them, just drop them an email at [email protected]

UPDATE: Currently Github requires support requests to be created here: https://support.github.com/contact

Solution 2 - Github

5 step to do what you want if you made the pull request from a forked repository:

  1. reopen the pull request
  2. checkout to the branch which you made the pull request
  3. reset commit to the last master commit(that means remove all you new code). Command: git reset --hard commit_hash_here
  4. git push --force
  5. delete your forked repository which made the pull request

And everything is done, good luck!

Solution 3 - Github

This is the reply I received from Github when I asked them to delete a pull request:

"Thanks for getting in touch! Pull requests can't be deleted through the UI at the moment and we'll only delete pull requests when they contain sensitive information like passwords or other credentials."

Solution 4 - Github

It's very easy actually:

You can empty it, that's the best you could do.

  1. Go to your local

  2. Copy your local branch unwanted-branch (against which the PR was opened) to a new branch new-branch. This copying is relevant if you want to back it up for any reason. Otherwise go to step 3.

    • $ git branch -b new-branch
    • $ git merge unwanted-branch
    • $ git push
  3. Empty the unwanted-branch

    • $ git checkout unwanted-branch
    • $ git reset --hard HEAD~n #n is the number of commit the branch has
    • $ git push -f

Enjoy, your PR is empty and closed now ;). Go to remote and delete the unwanted-branch if it bothers you.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionAristonaView Question on Stackoverflow
Solution 1 - GithubNevik RehnelView Answer on Stackoverflow
Solution 2 - GithubWokoView Answer on Stackoverflow
Solution 3 - GithubALI ABU FOULView Answer on Stackoverflow
Solution 4 - GithubedamView Answer on Stackoverflow