31

The following situation arises from time to time…

I git checkout -b experiment, commit some experimental changes, and open a pull request. After some discussion, the pull request is rejected.

If I were now to delete the remote branch, would this render the diff inaccessible at some point, or does GitHub ensure that commits which appear in pull requests are not garbage collected even if they don't appear on any branch?

I would like to delete dead branches, but only if doing so will not diminish the historical value of rejected pull requests.

davidchambers
  • 23,918
  • 16
  • 76
  • 105

1 Answers1

38

No, they will not be gc's because they're not wholly unreferenced even if you delete your branch.

Github creates a branch (actually, two) for every pull request. They're in a non-default namespace so you dont usually get them when you pull (or fetch) from the repo.

To see how this looks in practice, do a git ls-remote <REMOTE>, where <REMOTE> is either the name of a remote (if it's one your repo knows) or the URL (it doesn't need to be git remote added for this to work). This remote should have some pull requests, or you won't be able to see what I mean.

This will list all refs on the remote (all branches and tags), and you will see some refs like refs/pull/<number>/head and refs/pull/<number>/merge. Those refer to the latest commit in the PR and the commit at which it was merged in, respectively.

Nevik Rehnel
  • 49,633
  • 6
  • 60
  • 50
  • Nice info! Is this documented somewhere in Githubs's site or blog? Or how did you know? Thanks – Jorge Orpinel Pérez Mar 25 '21 at 04:38
  • 1
    @JorgeOrpinel It is kind of documented at https://docs.github.com/en/github/authenticating-to-github/keeping-your-account-and-data-secure/removing-sensitive-data-from-a-repository "You can't do anything about existing clones or forks of your repository, but you can permanently remove cached views and references to the sensitive data in pull requests on GitHub by contacting GitHub Support or GitHub Premium Support." (having to ask the support to do it means it does not happen automatically through a typical garbage collect as it happens in default local git install) – Patrick Mevzek Jun 08 '21 at 01:19
  • It is documented at https://docs.github.com/en/github/collaborating-with-pull-requests/reviewing-changes-in-pull-requests/checking-out-pull-requests-locally#modifying-an-inactive-pull-request-locally – philb Jul 12 '21 at 21:35