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
)
how can i check write access to a git repository, if i do have a clone of it? A very easy way to check is whether you see an edit 'pencil' icon in the top right of the README.MD on the main Code page of the repo (scroll down to it if there's a long list of top level files/folders).
In order to push a Git branch to remote, you need to execute the “git push” command and specify the remote as well as the branch name to be pushed. If you are not already on the branch that you want to push, you can execute the “git checkout” command to switch to your branch.
Open Security for a repository You set Git repository permissions from Project Settings>Repositories. Open the web portal and choose the project where you want to add users or groups. To choose another project, see Switch project, repository, team. Open Project settings>Repositories.
git directory that contains metadata about the repository. That's what Git uses to determine where to push your changes.
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
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" }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With