dkc dkc - 3 months ago 21
Bash Question

Shell script for authenticating github credential

I have shell script and I am cloning master branch into some directory. However I have other steps to follow once I successfully cloned master branch in specified directory. Is there anyway with below command that it returns something true|false so I can do other steps?

git clone -b master https://github.com/someuser/project.git /path/to/dir


I have other way around for this but wanted to know if there is some possibility of this.

Thanks!

Answer

The git clone command uses exit code 0 on success and non-zero on failure, just like any well-behaving program. You can use this in conditional statements, for example:

if git clone -b master repourl /path/to/dir; then
    # clone successful -> run setup script
else
    echo fatal: could not clone repo
fi