GitHub keeps a git references to every pull request apart from the branch. Reference
If you need the commits in a PR again (even with a deleted branch), these git aliases can help.
Copy the aliases to ~/.gitconfig
and use as follows:
# Fetch the branch for pull request #24 under a remote tracking branch of pr/24
git fetch-pr 24
# Checkout the branch
git checkout pr/24
# Delete all local PR branches after you're done
git delete-prs
Also included in karlhorky/dotfiles.
If you need to fetch all GitHub pull requests as local branches use Fetch all GitHub pull requests to local tracking branches