Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save GregTheGreek/754ed6c4c9574bb3ab101af5d2ce1280 to your computer and use it in GitHub Desktop.
Save GregTheGreek/754ed6c4c9574bb3ab101af5d2ce1280 to your computer and use it in GitHub Desktop.
Git clone 2
function gc2 {
url="$1"
download_path="/YOUR/PATH/"
# Remove protocol and .git, replace : with / for SSH
full_path=$(echo "$url" | sed -E 's#(git@|https?://)##; s#:#/#; s#\.git$##')
go_to_path="${download_path}${full_path}"
# Try to clone, capture output and error
output=$(git clone "$url" "$go_to_path" 2>&1)
clone_status=$?
if [[ $clone_status -ne 0 ]]; then
if echo "$output" | grep -q "already exists and is not an empty directory"; then
# Silently ignore this specific error
:
else
# Print the error and exit
echo "$output" >&2
return $clone_status
fi
fi
cd "$go_to_path"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment