GitHub – Add to a Pull Request After Source Repo is Deleted

github

I've opened a pull request (PR) on a repo, but then managed to accidentally delete the branch I initiated the request from. The maintainer of the project has requested I make a couple changes.. now I'm stuck.

Github still has the PR, but now shows the source of the branch as "unknown repository".

I was able to recover the exact commit and re-push that (it has the same commit hash as the commit in the PR), but it still shows as "unknown repository".

Is there a way to push directly into the PR itself?

Best Answer

You could try the steps outlined in this issue to pull the the branch from the PR:

So to update a PR, even if you have removed the original remote branch out of which the PR was created, you just need to:

  • Fetch the PR (git fetch pull/<id>/head:branchname and git checkout branchname).
  • Add new commits, amend, rebase, do whatever you like.
  • Push or push force (git push remote +branch).

And after that the PR will be automagically updated :)

This support page also talks about how to recreate a branch from a PR, although it ends with creating a new PR (so worst case you could grab the old branch, then close that PR and open a new one).