I forked a project, created a new branch from master, made changes and created a pull request to the original project. But suddenly I forgot I created this pull request and deleted my fork completely from remote (GitHub) and from my PC as well. How can I recreate a branch (or a fork) from a pull request in order to add a change and let it merge?
- Is the PR still open? Afair if you delete the branch in your fork, the PR is automatically closed. Not sure what happens if you delete the fork instead.Vampire– Vampire2016-10-05 14:29:17 +00:00Commented Oct 5, 2016 at 14:29
- Still open, just with note: "from me/branch deleted to project/master"aleskva– aleskva2016-10-05 14:30:45 +00:00Commented Oct 5, 2016 at 14:30
- *exactly "to project:master from unknown repository"aleskva– aleskva2016-10-05 14:53:04 +00:00Commented Oct 5, 2016 at 14:53
- Does this answer your question? Recover a commit sent as a pull-request from a deleted fork on GitHubInigo– Inigo2021-12-17 08:25:23 +00:00Commented Dec 17, 2021 at 8:25
2 Answers
There are two things you can do:
1. Contact GitHub support
While trying out my solution for you I deleted a fork where I myself had a PR still pending and had the same situation than you.
There is currently no way to reattach to that PR, besides contacting GitHub support. They can restore the deleted fork which will also reattach it to the pending PR. Then you can simply clone your fork, change your PR branch and push.
It was a matter of minutes in my case until GitHub staff responded to the contact form. applauding to GitHub
2. Make a new PR
If you don't want to bother GitHub support or they are too slow for you or are unwilling, you can do the following:
- recreate your fork
- recreate your branch from the pull request by doing
git fetch <your configured remote for upstream> refs/pull/<your PR number>/head:<your branchname>
This will recreate the PR branch for you locally, then change whatever you want to change, close the original PR and open a new one.
3 Comments
fatal: 'upstream' does not appear to be a git repository fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists.origin and the master repo is called upstream.One way to fix this:
$ mkdir repo $ git init; git remote add origin [email protected]:original/repo.git # not your fork Now open up .git/config and add this line:
fetch = +refs/pull/*/head:refs/remotes/origin/pr/* so it reads:
[remote "origin"] url = [email protected]:original/repo.git fetch = +refs/heads/*:refs/remotes/origin/* fetch = +refs/pull/*/head:refs/remotes/origin/pr/* Then run
$ git fetch origin $ git checkout origin/pr/<your pr number, as shown in their github repo> Then just add a new remote to your fork, and push up the branch
5 Comments
git fetch origin produces this: Permission denied (publickey). fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists.pr/9608. Perfect!