Kanji
・ Cloud engineer / freelance ・ Born in 1993 ・ Born in Ehime Prefecture / Lives in Shibuya-ku, Tokyo ・ AWS history 5 years Profile details
gh auth login
Table of contents
~/.config/gh/hosts.yml.${プロファイル名}
~/.config/gh/config.yml
git config --global 'credential.https://github.com.helper' '' git config --global --add 'credential.https://github.com.helper' '!gh auth git-credential'
create-profile
switch-profile
aliases
gh auth status
~/.config/gh/hosts.yml
~/.config/gh/hosts.yml.${Profile name}
git_protocol: https aliases: create-profile: '!gh auth status && read -p "Do you create this profile? (y/N): " yn; case "$yn" in [yY]*) cp ~/.config/gh/hosts.yml ~/.config/gh/hosts.yml.$1 && echo "[INFO] New hosts file created: ~/.config/gh/hosts.yml.$1";; esac' switch-profile: '!if [ -e ~/.config/gh/hosts.yml.$1 ]; then cp ~/.config/gh/hosts.yml.$1 ~/.config/gh/hosts.yml && gh auth status && echo "[INFO] Hosts file switched"; else echo "[ERROR] Hosts file not found: ~/.config/gh/hosts.yml.$1"; fi'
# Profile creation command yq -o yaml -i '.aliases += {"create-profile": "''''!gh auth status && read -p \"Do you create this profile? (y/N): \" yn; case \"$yn\" in [yY]*) cp ~/.config/gh/hosts.yml ~/.config/gh/hosts.yml.$1 && echo \"[INFO] New hosts file created: ~/.config/gh/hosts.yml.$1\";; esac''''"}' ~/.config/gh/config.yml # Profile switching command yq -o yaml -i '.aliases += {"switch-profile": "''''!if [ -e ~/.config/gh/hosts.yml.$1 ]; then cp ~/.config/gh/hosts.yml.$1 ~/.config/gh/hosts.yml && gh auth status && echo \"[INFO] Hosts file switched\"; else echo \"[ERROR] Hosts file not found: ~/.config/gh/hosts.yml.$1\"; fi''''"}' ~/.config/gh/config.yml
gh create-profile ${Profile name}
y
github.com ✓ Logged in to github.com as xxxxxxxxxx (oauth_token) ✓ Git operations for github.com configured to use https protocol. ✓ Token: ******************* Do you create this profile? (y/N): y [INFO] New hosts file created: ~/.config/gh/hosts.yml.xxxx
gh switch-profile ${Profile name}
# When a profile exists github.com ✓ Logged in to github.com as xxxxxxxxxx (oauth_token) ✓ Git operations for github.com configured to use https protocol. ✓ Token: *******************c [INFO] Hosts file switched # If there is no profile [ERROR] Hosts file not found: ~/.config/gh/hosts.yml.test