Skip to content

Instantly share code, notes, and snippets.

@pangpond
Created October 15, 2025 14:30
Show Gist options
  • Save pangpond/e65ddd8abc7bc5c11b0babf98dc2cb57 to your computer and use it in GitHub Desktop.
Save pangpond/e65ddd8abc7bc5c11b0babf98dc2cb57 to your computer and use it in GitHub Desktop.
ghq to get the repository and cd to that path
# Remove any existing gq alias/function to avoid conflicts
unalias gq 2>/dev/null
unfunction gq 2>/dev/null
gq() {
local url="$1"
if [ -z "$url" ]; then
echo "Usage: gq <github-url>"
return 1
fi
# Use ghq to get the repository path
local full_path=$(ghq list -p -e "$url" 2>/dev/null)
if [ -n "$full_path" ] && [ -d "$full_path" ]; then
echo "📂 Repo exists at: $full_path"
echo "Pulling latest changes..."
cd "$full_path" || return 1
git pull
else
echo "📥 Cloning repository..."
ghq get -p "$url"
if [ $? -eq 0 ]; then
full_path=$(ghq list -p -e "$url")
if [ -n "$full_path" ]; then
cd "$full_path" || return 1
fi
else
echo "❌ Failed to clone repository"
return 1
fi
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment