How can I check write access to a remote Git repository ("can I push?")
Solution 1:
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
Solution 2:
With the latest GitHub API you can check the permissions on a particular repo for a USERNAME (yours or another user) with the following command (you'll need to authenticate using your personal access token) e.g.:
curl -u your_username:your_access_token \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/octocat/hello-world/collaborators/USERNAME/permission
The response will show what permissions the USERNAME has for that repo. Otherwise it will report:
"message": "Not Found"
Note that you should have push access to the repo in question or it will fail with
{
"message": "Must have push access to view collaborator permission.",
"documentation_url": "https://docs.github.com/rest/reference/repos#get-repository-permissions-for-a-user"
}
Solution 3:
You may perform git push git+ssh://host.org/path/to/repo some_ref
without cloning.
But remember that pushing a chain of commits and update remote references are two different operations and you may have a permission for the former, but no permission for the latter. Also certain references could be unmodifiable.