简体   繁体   English

检查shell脚本中是否存在git repo

[英]Check if a git repo exists in a shell script

Is there a way to check if a git repo exists using a bash or csh script? 有没有办法检查使用bash或csh脚本是否存在git repo? I know that we can use git ls-remote <repository> to check the existence of the remote repo. 我知道我们可以使用git ls-remote <repository>来检查git ls-remote <repository>是否存在。 But I'd like to somehow do this programatically in a shell script. 但我想以某种方式在shell脚本中以编程方式执行此操作。

You can write the command in the script itself: 您可以在脚本本身中编写命令:

~$ git ls-remote <existing_repo> -q
~$ echo $?
0

0 means that the repo was found, otherwise you'll get a non-zero value. 0表示找到了回购,否则您将获得非零值。

-q is for: -q适用于:

quiet (Do not print remote URL to stderr.) 安静(不要打印到stderr的远程URL。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM