如何检查对远程 Git 存储库的写访问权限(“我可以推送吗?”)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22811045/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How can I check write access to a remote Git repository ("can I push?")
提问by Yang Meyer
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.
我正在构建一个(有些有限的)Git 客户端。要设置存储库,请输入远程存储库的 URL。我想检查用户是否对该存储库具有读写访问权限。如果没有,我会显示一个身份验证对话框。
I check 'read' accesswith git ls-remote <url>
.
我检查“读”访问用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
)
有没有一种类似的方法来检查“写”访问,而不先克隆 repo?(我知道我可以git clone <url>
,然后git push --dry-run
)
回答by guyskk
If the git repo is in github, open any file in the repo, then click 'edit', github will show something like this:
如果 git repo 在 github 中,打开 repo 中的任何文件,然后单击“编辑”,github 将显示如下内容:
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
您正在编辑您没有写入权限的项目中的文件。我们已经为这个项目创建了一个分支,供您提交您提出的更改。提交对此文件的更改会将其写入 fork 中的新分支,因此您可以发送拉取请求。在此处输入代码
回答by user3159253
You may perform git push git+ssh://host.org/path/to/repo some_ref
without cloning. But see my comment above
您git push git+ssh://host.org/path/to/repo some_ref
无需克隆即可执行。但是看我上面的评论