[英]git: how can I programmatically tell if a repo can be pushed?
I see this output from a cloned repo for which I have write permission: 我看到了我具有写权限的克隆存储库的以下输出:
$~/g/cad --> git push
Everything up-to-date
and this output for one for which I don't: 而我没有的输出:
$~/g/opentx --> git push
Username for 'https://github.com':
How can I tell programatically that a particular repository has write permission? 如何以编程方式告知特定存储库具有写权限?
The only way to tell if you have write permission to a remote repository is to try writing something there by pushing a commit or a tag or something. 告诉您是否具有对远程存储库的写许可权的唯一方法是尝试通过推送提交或标记或其他内容来在其中写入某些内容。
I guess you try to push a tag, then delete the tag: 我猜您尝试推送标签,然后删除标签:
git tag a-test-tag
git push origin a-test-tag
git push --delete origin a-test-tag
If the push
is successful you probably have write permissions on the remote repository (I say "probably" because you may only be able to update tags but not push commits, or you may only be able to push commits to specific branches, etc). 如果
push
成功,则您可能具有对远程存储库的写权限(我说“大概”是因为您可能仅能更新标签但不能推送提交,或者您仅能够将提交推送到特定分支等)。
You can cause git to fail if authentication is required, rather than prompting for credentials, by setting the GIT_ASKPASS
environment variable to true
: 通过将
GIT_ASKPASS
环境变量设置为true
,可以在需要身份验证而不是提示输入凭据的情况下导致git失败:
GIT_ASKPASS=true git push origin a-test-tag
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.