What access permission is needed to create a Pull Request to public repositories?

What permission do we need to send a PR to public repositories which we have only read access? Only read or need write as well?

These two statements look conflicting to me.

Creating a pull request - GitHub Docs

Anyone with read permissions to a repository can create a pull request

Note : To open a pull request in a public repository, you must have write access to the head or the source branch

Hello. :wave:

That means you need to have write access to open a pull request and change the code directly in that public repository, which I something I don’t think GitHub offers for security reasons.

To contribute to a public repository you will have to fork that repository, creating your version which you will have write access to, write to that version, and then send a pull request from that version back to the original repository.

That’s how you usually go about it, but look out for CONTRIBUTING.md, LICENSE, and, or, CODE_OF_CONDUCT.md files, if a repository has those you should read them first before submitting any pull request to make sure you’ve followed all the necessary steps they require for a pull request, and you should read the README.md too but that’s in the name so. :slightly_smiling_face:

Do keep in mind that if a repository doesn’t have a LICENSE, even if it’s visible and public, it’s not considered open-source since it doesn’t have a LICENSE, in that case, I would suggest opening an issue or contacting the owner directly and asking for permission to contribute or asking them for a license.

If you have a public repository and want to give write access to a contributor to edit code directly on the repository you can invite them under settings > manage access.

Hope that helped. :grinning:


Thank you thinkverse. It’s very clear now.
I was wondering how a PR to Read-only repos works. When I do something like this:

git clone hogehoge  # a repository which I only have Read access
touch test.txt
git add .
git commit -m 'test'
gh pr create  # make a PR

It turned out that a fork is automatically created and any of my local branches are set up to track the fork, instead of the original repo.
Hence, I think a direct PR to Read-only repos is simply impossible (i.e. PR is done through a fork). What’s possible is:

  • Read access + PR through a fork
  • Write access + direct PR

I also appreciate the detailed explanation on the documentations. It’s of great help :slight_smile:

Correct, that is in fact how the git clone command works, this excerpt is taken from the documentation on git clone.

and creates and checks out an initial branch that is forked from the cloned repository’s currently active branch.

I’m glad I could help, good luck with your journey. :+1:


Thank you! It’ clear now.

Glad I could help, if one post helped you solved it, please mark it as the solution, it will help people looking around for the same issue in the future. :slightly_smiling_face:

1 Like