Skip to content

Instantly share code, notes, and snippets.

@joubertredrat
Created November 18, 2021 00:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joubertredrat/7ed396c410a8860689c8022c224f98a2 to your computer and use it in GitHub Desktop.
Save joubertredrat/7ed396c410a8860689c8022c224f98a2 to your computer and use it in GitHub Desktop.
Clone a Github repository into a new directory with user as prefix
#!/bin/sh
# git-clone-github
# Clone a Github repository into a new directory with user as prefix
# Usage: git clone-github github-repo-url
set -e
clone_url=$1
if [[ $clone_url != https://github.com/* && $clone_url != http://github.com/* ]]
then
echo "invalid clone url, expected github url"
exit -1
fi
folder_separator="__"
user_project=$(sed "s|http://||g; s|https://||g; s|github.com/||g; s|.git||g;" <<< $clone_url)
clone_path=$(sed "s|/|$folder_separator|g" <<< $user_project)
git clone $clone_url $clone_path
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment