Skip to content

Instantly share code, notes, and snippets.

@darinkishore
Created May 31, 2025 21:35
Show Gist options
  • Select an option

  • Save darinkishore/cfe2ae03d7bdd79258b2254cc5ae6f37 to your computer and use it in GitHub Desktop.

Select an option

Save darinkishore/cfe2ae03d7bdd79258b2254cc5ae6f37 to your computer and use it in GitHub Desktop.
GitHub CLI authentication helper - provides interactive options for web browser or token-based authentication
#!/usr/bin/env bash
# Helper script to authenticate with GitHub CLI
set -euo pipefail
echo "GitHub CLI Authentication Helper"
echo "================================"
echo ""
echo "This will help you authenticate with GitHub to clone private repos."
echo ""
# Check if already authenticated
if gh auth status &>/dev/null; then
echo "✓ Already authenticated with GitHub!"
gh auth status
exit 0
fi
echo "Choose authentication method:"
echo "1) Login with web browser (recommended)"
echo "2) Paste an authentication token"
echo ""
read -p "Select (1-2): " choice
case $choice in
1)
echo "Opening browser for authentication..."
gh auth login --web
;;
2)
echo "Create a token at: https://github.com/settings/tokens"
echo "Required scopes: repo, read:org"
gh auth login --with-token
;;
*)
echo "Invalid choice"
exit 1
;;
esac
echo ""
echo "✓ Authentication complete!"
gh auth status
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment