368

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?

random
  • 9,774
  • 10
  • 66
  • 83
Aristona
  • 8,611
  • 9
  • 54
  • 80
  • 3
    No. You can only close it. – Eugene Ryzhikov Aug 19 '13 at 16:14
  • 12
    GitHub account and UI related questions are better for http://WebApps.StackExchange.com or directly to their support – random Aug 26 '13 at 00:41
  • 3
    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 '17 at 20:16
  • 5
    Great Q and another victim of the SO mandarins. Great answers too. – RichieHH Mar 04 '20 at 22:04

4 Answers4

393

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 support@github.com

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

Community
  • 1
  • 1
Nevik Rehnel
  • 49,633
  • 6
  • 60
  • 50
  • 70
    They(Github staff) only delete pull requests that contain sensitive data. – Yousha Aleayoub Oct 20 '17 at 16:00
  • 6
    Some useful information: https://help.github.com/articles/removing-sensitive-data-from-a-repository/ "... you can permanently remove all of your repository's cached views and pull requests on GitHub by contacting GitHub Support." – Justin Domnitz Apr 11 '18 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 – Erik Aronesty May 06 '19 at 21:24
  • I know this is an old question but have you tried delete your github account and re-create it? From the documentation, when you delete your account, github said you automatically delete all your pull request made in other repository. But this means you have to start your "new life" on github. I think this is the only way. Hopefuly someone open this question and put this answer below. – MaXi32 Oct 31 '19 at 08:34
  • 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 '19 at 05:21
  • 65
    Guess I'll have to add my SSN + date of birth to get this PR deleted :( – Neel Apr 28 '20 at 01:09
  • 1
    I assume that's a GitHub philosophy, since you can delete that info in git – joel Sep 03 '20 at 15:33
  • 1
    https://support.github.com/request >> **Remove data from a repository I own or control** >> **Remove pull requests** – Jess Chen Dec 03 '21 at 07:20
43

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!

Ufos
  • 3,083
  • 2
  • 32
  • 36
Woko
  • 1,521
  • 12
  • 16
  • 4
    This works even if the repo is not a fork. Just make sure you back up the branch first. – slajma Oct 23 '20 at 12:00
  • 25
    This does not actually delete the PR. It simply closes the PR and the PR still remains visible in logs – Ishan Jain Mar 31 '21 at 17:23
  • 2
    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 - https://github.com/isaacs/github/issues/361#issuecomment-219088644 – Darshan L Jul 04 '21 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 '21 at 06:38
  • The PR is still listed, but at least without a code pushed there before. – Pavlo Zhukov Jul 07 '22 at 12:34
  • 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' – Mark Adamson Jan 09 '23 at 14:36
32

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

ALI ABU FOUL
  • 431
  • 4
  • 3
  • 24
    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! –  Apr 06 '22 at 19:59
-3

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.

edam
  • 910
  • 10
  • 29
  • 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. – Yılmaz Alpaslan Jan 25 '22 at 18:07
  • 20
    git has no problem with deleting branches or commits. It's GitHub that won't allow deleting PRs here. – Ordoshsen Mar 28 '22 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" – Jonatan Cloutier Jun 07 '22 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 04 '22 at 14:42