0

I want to automate some setup tasks. When a team member writes setup which is our internal command, a couple of things would be done.

One of those things is to make sure the latest version of our infra repository is either pulled or cloned onto his laptop.

But if he does not have the infra repository cloned, I want to clone it based on his permission.

In other words here's what I want:

# This command would run if he has write access
git clone git@github.com:company/infra

If the above command failed, I want to run this command

git clone https://github.com/company/infra

How can I run the second line, only if the first line failed?

1 Answers1

3

Combine the commands with ||:

git clone git@github.com:company/infra || \
git clone https://github.com/company/infra

See What are the shell's control and redirection operators? for details.

Stephen Kitt
  • 434,908