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

问题描述 投票:3回答:1

有没有办法检查使用bash或csh脚本是否存在git repo?我知道我们可以使用git ls-remote <repository>来检查远程仓库的存在。但我想以某种方式在shell脚本中以编程方式执行此操作。

git bash
1个回答
4
投票

您可以在脚本本身中编写命令:

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

0表示找到了回购,否则您将获得非零值。

-q适用于:

安静(不要打印到stderr的远程URL。)

© www.soinside.com 2019 - 2024. All rights reserved.