简体   繁体   English

git:如何以编程方式判断回购协议是否可以推送?

[英]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.

相关问题 将数据推送到裸git仓库时,如何自动将数据推送到git-repo? - How can I automatically push the data to a git-repo when it's pushed to a bare git repo? 我意外地用错误的用户帐户推送到git repo。 如何撤消或更改用户? - I've accidently pushed to a git repo with the wrong user account. How can I undo it or change the user? 如何在执行提交时确保git config文件被推送到仓库? - How can I make sure git config file gets pushed to repo when doing commits? 在git服务器上找不到推送的仓库 - Can't find pushed repo on git server 进行了git commit,git pull并将我的更改推送到了仓库。 我如何发送对我提交的请求的请求 - did a git commit, git pull and pushed my changes to the repo. How can i send a Pull request for the one that i committed 我怎么知道git commit在仓库中会使用多少额外的磁盘空间? - How can I tell how much extra disk space a git commit will use in the repo? 如何告诉PyCharm不要将node_modules发送到git repo? - How can I tell PyCharm to not send node_modules to git repo? "如何将 git repo 中的目录镜像到另一个 git repo?" - How can I mirror a directory in a git repo into another git repo? 如何修复我的本地存储库,以便我可以保存尚未推送到主 git 存储库的提交的工作? - How do I fix my local repo so I can save work from commits that haven’t been pushed to the master git repo? 推到git裸仓库,我无法从其他机器上提取更改 - Pushed to git bare repo and I can't pull changes from other machines
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM