Skip to content

Instantly share code, notes, and snippets.

@third774
Created July 12, 2025 06:04
Show Gist options
  • Save third774/3ec2179196d91c66f54ecda9fed7931c to your computer and use it in GitHub Desktop.
Save third774/3ec2179196d91c66f54ecda9fed7931c to your computer and use it in GitHub Desktop.
# git add remote
gar() {
local url=$(pbpaste)
# Validate URL format (basic git remote URL patterns)
if [[ ! "$url" =~ ^(https://|git@|ssh://git@).+\.git$ ]] && [[ ! "$url" =~ ^(https://|git@).+/.+$ ]]; then
echo "Error: Invalid git remote URL format in clipboard"
echo "Expected formats: https://github.com/user/repo.git or [email protected]:user/repo.git"
return 1
fi
local username=$(echo "$url" | sed 's/.*[:/]\([^/]*\)\/[^/]*$/\1/')
if git remote add "$username" "$url" 2>/dev/null; then
echo "✓ Added remote '$username' -> $url"
else
echo "Error: Failed to add remote '$username' (may already exist)"
return 1
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment