BigBrownBear00
BigBrownBear00

Reputation: 1480

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? I know that we can use git ls-remote <repository> to check the existence of the remote repo. But I'd like to somehow do this programatically in a shell script.

Upvotes: 8

Views: 10762

Answers (1)

Maroun
Maroun

Reputation: 95968

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.

-q is for:

quiet (Do not print remote URL to stderr.)

Upvotes: 8

Related Questions