Created
February 24, 2024 13:59
-
-
Save naranyala/80f6345ab91cc9541de3752643369e0c to your computer and use it in GitHub Desktop.
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
#!/bin/bash | |
# Check if a GitHub URL is provided | |
if [ -z "$1" ]; then | |
echo "Usage: $0 <GitHub Repo URL>" | |
exit 1 | |
fi | |
# Remove "http://" or "https://" | |
url_no_protocol=$(echo $1 | sed 's/https\?:\/\///') | |
# Remove ".git" from the end, if present | |
url_no_git=$(echo $url_no_protocol | sed 's/\.git$//') | |
# Extract username and reponame from the GitHub URL | |
url_parts=($(echo $url_no_git | tr '/' ' ')) | |
username=${url_parts[1]} | |
reponame=${url_parts[2]} | |
# Formulate the custom name without the GitHub domain | |
custom_name="${username}-${reponame}" | |
# Clone the repository with the custom name and --depth=1 | |
git clone --depth=1 $1 $custom_name | |
# Let the user know it's done | |
echo "Repository cloned as: $custom_name" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment