380

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?

4
  • 3
    No. You can only close it. Aug 19, 2013 at 16:14
  • 12
    GitHub account and UI related questions are better for WebApps.StackExchange.com or directly to their support
    – random
    Aug 26, 2013 at 0:41
  • 4
    You can get rid off all pull requests (and other things like LFS files) by deleting and recreating the repository. Most of the time you cannot afford this but it can help if you mess up early on.
    – Machta
    Jan 11, 2017 at 20:16
  • 6
    Great Q and another victim of the SO mandarins. Great answers too.
    – RichieHH
    Mar 4, 2020 at 22:04

4 Answers 4

402

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

8
  • 71
    They(Github staff) only delete pull requests that contain sensitive data. Oct 20, 2017 at 16:00
  • 6
    Some useful information: help.github.com/articles/… "... you can permanently remove all of your repository's cached views and pull requests on GitHub by contacting GitHub Support." Apr 11, 2018 at 18:29
  • 10
    So sad. I submit a bad PR about once every week because I'm maintaining a forked repo and the default PR is to the head. At some point we'll need to branch off from the mai, but for now... zillion closed pr's May 6, 2019 at 21:24
  • 4
    For what it's worth, I contacted GitHub support today to request deletion of a PR that was submitted by mistake to another repository where I'm an admin. They deleted it for me and were super nice. :)
    – Marc.2377
    Nov 13, 2019 at 5:21
  • 71
    Guess I'll have to add my SSN + date of birth to get this PR deleted :(
    – Neel
    Apr 28, 2020 at 1:09
44

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!

6
  • 4
    This works even if the repo is not a fork. Just make sure you back up the branch first.
    – slajma
    Oct 23, 2020 at 12:00
  • 27
    This does not actually delete the PR. It simply closes the PR and the PR still remains visible in logs
    – Ishan Jain
    Mar 31, 2021 at 17:23
  • 3
    An important point in this approach is to make sure you reopen the PR before you force push. ie step1 is a must before you go to next step. Otherwise, once you have force pushed your changes, you cant reopen the PR. If in case, you didnt perform step1 and force pushed, still you can reopen with tedious workaround - github.com/isaacs/github/issues/361#issuecomment-219088644
    – Darshan L
    Jul 4, 2021 at 18:44
  • It did not work even though I followed the steps including the step 1. The PR becomes just a closed state and still listed in the closed PR list.
    – kamae
    Nov 13, 2021 at 6:38
  • 1
    Unfortunately if used on a non-forked PR this technique doesn't completely clear out the old code. You'll end up with a message like this at the bottom of the closed PR some-user force-pushed the some-branch branch from 12bcd456 to 455abc 2 minutes ago Those are the SHAs and provide a direct link to the code that was 'removed' Jan 9 at 14:36
35

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."

1
  • 29
    So the solution for this missing feature is to edit a pull request to add a social security number to it -- it may not have to be your own!
    – user11638666
    Apr 6, 2022 at 19:59
-2

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.

4
  • 3
    This empties the PR in case sensitive data was publishes with the PR, but OP wants to completely delete the PR in both contribution activity and closed PRs list of the repository. Apparently it's not possible to do so. Jan 25, 2022 at 18:07
  • 21
    git has no problem with deleting branches or commits. It's GitHub that won't allow deleting PRs here.
    – Ordoshsen
    Mar 28, 2022 at 13:52
  • 3
    This is not working, even for just removing content, although the pr look empty, you can still compare the force push "commit diff" Jun 7, 2022 at 12:59
  • just an additional hint: don't close the PR first, then it will ignore anything you do and won't let you reopen it either after you mess with the branch
    – fifaltra
    Oct 4, 2022 at 14:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.