Skip to content

Instantly share code, notes, and snippets.

@sramam
Created September 2, 2025 21:09
Show Gist options
  • Select an option

  • Save sramam/4b9ba11f4f711915e391b87e125922dd to your computer and use it in GitHub Desktop.

Select an option

Save sramam/4b9ba11f4f711915e391b87e125922dd to your computer and use it in GitHub Desktop.
Setup github profile
#!/usr/bin/env bash
set -euo pipefail
# Usage: setup-gh <profile_name> <profile_dir>
# Example: setup-gh work ~/dev/profiles/work
if [ $# -ne 2 ]; then
echo "Usage: $0 <profile_name> <profile_dir>"
exit 1
fi
PROFILE_NAME="$1"
PROFILE_DIR="$2"
ABS_PROFILE_DIR="$(realpath "$PROFILE_DIR")"
mkdir -p "$ABS_PROFILE_DIR"
# Generate SSH key for this profile
KEY_PATH="$ABS_PROFILE_DIR/${PROFILE_NAME}_id_ed25519"
if [ ! -f "$KEY_PATH" ]; then
ssh-keygen -t ed25519 -C "$PROFILE_NAME@github" -f "$KEY_PATH" -N ""
echo "SSH key generated at $KEY_PATH"
else
echo "SSH key already exists at $KEY_PATH"
fi
# Add ssh config entry
SSH_CONFIG="$HOME/.ssh/config"
HOST_ALIAS="github-$PROFILE_NAME"
if ! grep -q "$HOST_ALIAS" "$SSH_CONFIG" 2>/dev/null; then
{
echo ""
echo "Host $HOST_ALIAS"
echo " HostName github.com"
echo " User git"
echo " IdentityFile $KEY_PATH"
echo " IdentitiesOnly yes"
echo " AddKeysToAgent yes"
} >> "$SSH_CONFIG"
echo "Added SSH config for $HOST_ALIAS"
else
echo "SSH config for $HOST_ALIAS already exists"
fi
# Configure git inside the profile directory
(
cd "$ABS_PROFILE_DIR"
git config user.name "$PROFILE_NAME"
git config user.email "[email protected]"
git config core.sshCommand "ssh -i $KEY_PATH -F $HOME/.ssh/config -o IdentitiesOnly=yes"
)
echo ""
echo "✅ Setup complete for profile: $PROFILE_NAME"
echo "Public key for GitHub:"
echo ""
cat "$KEY_PATH.pub"
echo ""
echo "➡️ Add this key to your GitHub account (Settings → SSH and GPG keys)."
echo "➡️ Use clone URLs like: git@github-$PROFILE_NAME:<youruser>/<repo>.git"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment