How can I check write access to a remote Git repository ("can I push?")

Yang Meyer picture Yang Meyer · Apr 2, 2014 · Viewed 104.4k times · Source

I am building a (somewhat limited) Git client. To set up a repository, you enter the URL to the remote repo. I want to check whether the user has read+write access to that repository. If not, I present an authentication dialog.

I check 'read' access with git ls-remote <url>.

Is there an analogous way to check 'write' access, without cloning the repo first? (I know I could git clone <url> and then git push --dry-run)

Answer

guyskk picture guyskk · Oct 30, 2016

If the git repo is in github, open any file in the repo, then click 'edit', github will show something like this:

You’re editing a file in a project you don’t have write access to. We’ve created a fork of this project for you to commit your proposed changes to. Submitting a change to this file will write it to a new branch in your fork, so you can send a pull request.enter code here