GitFolder
Checks out from gitlab based on the git http url, and makes the same folder structure on your local machine.
#!/usr/bin/env bash
set -euo pipefail
# Check that exactly one argument (the Git repo URL) is provided
if [[ $# -eq 0 ]]; then
echo "Usage: $0 <git-repo-url>"
exit 1
fi
url="$1"
# Strip the protocol (e.g., https:// or ssh://) from the URL
url_no_protocol="${url#*://}"
# Remove the GitLab domain from the URL path, leaving only the repo path
# For example, gitlab.com/roxorgaming/personal/... -> roxorgaming/personal/...
git_project="${url_no_protocol#gitlab.com/}"
# Define the base directory where repos will be stored (your home directory)
base_path="$HOME"
# Full local path for the repo, combining base path and repo path
full_path="$base_path/$git_project"
# Parent directory of the repo folder (used for creating directories)
parent_dir="${full_path%/*}"
if [ ! -d "$full_path" ]; then
mkdir -p "$parent_dir"
cd "$parent_dir"
# Clone the repository using SSH URL format
git clone "[email protected]:${git_project}.git"
else
# If repo folder exists, change to it and pull the latest changes quietly
cd "$full_path"
git pull > /dev/null
fi
# Update the folder's modification time to now (helps Finder sort by recent)
touch "$full_path"
echo "$full_path"
Last updated