Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to detect if a git clone failed in a bash script

How can I tell if a git clone had an error in a bash script?

git clone [email protected]:my-username/my-repo.git

If there was an error, I want to simply exit 1;

like image 370
Justin Avatar asked Dec 10 '12 01:12

Justin


People also ask

How do I check git bash?

Step 1: Go to Github repository and in code section copy the URL. Step 2: In the Command prompt, add the URL for your repository where your local repository will be pushed. Step 3: Push the changes in your local repository to GitHub. Here the files have been pushed to the master branch of your repository.

Why git clone is not working?

If you have a problem cloning a repository, or using it once it has been created, check the following: Ensure that the user has gone through initial GitCentric login and has the correct username, email, and ssh. This should return a usage message that refers to the config-branch, config-repo, and ls-repo commands.

What are git cloners?

git clone is primarily used to point to an existing repo and make a clone or copy of that repo at in a new directory, at another location. The original repository can be located on the local filesystem or on remote machine accessible supported protocols. The git clone command copies an existing Git repository.


1 Answers

Here are some common forms. Which is the best to choose depends on what you do. You can use any subset or combination of them in a single script without it being bad style.


if ! failingcommand
then
    echo >&2 message
    exit 1
fi

failingcommand
ret=$?
if ! test "$ret" -eq 0
then
    echo >&2 "command failed with exit status $ret"
    exit 1
fi

failingcommand || exit "$?"

failingcommand || { echo >&2 "failed with $?"; exit 1; }
like image 62
Jo So Avatar answered Oct 06 '22 00:10

Jo So