Created
June 28, 2025 10:04
-
-
Save GregTheGreek/754ed6c4c9574bb3ab101af5d2ce1280 to your computer and use it in GitHub Desktop.
Git clone 2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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