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

有些话、适合烂在心里 提交于 2020-05-09 18:06:31

问题


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)


回答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




回答2:


You may perform git push git+ssh://host.org/path/to/repo some_ref without cloning. But see my comment above



来源:https://stackoverflow.com/questions/22811045/how-can-i-check-write-access-to-a-remote-git-repository-can-i-push

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!