GH CLI multi-account switch
writed this article because I need drive two accouns of github, this year I wanted work in two place, but GITHUB CLI not shared any information in his docs. searching in google I founed many people with the same problem. then how a good development research many blogs and I found this solutions
George L. Yermulnik He was the creator of this solutions
Steps
1.- config.yml
in our computer look the path of this file
config.yml, the path usually this is in the next path Terminal
// in Mac
~/.config/gh/config.yml
// in Linux
~/.config/gh/config.yml
// in Windows
C:\Users\your-username\AppData\Roaming\GitHub CLIits content
Terminal
# What protocol to use when performing git operations. Supported values: ssh, https
git_protocol: https
# What editor gh should run when creating issues, pull requests, etc. If blank, will refer to environment.
editor:
# When to interactively prompt. This is a global config that cannot be overridden by hostname. Supported values: enabled, disabled
prompt: enabled
# A pager program to send command output to, e.g. "less". Set the value to "cat" to disable the pager.
pager:
# Aliases allow you to create nicknames for gh commands
aliases:
co: pr checkout
# The path to a unix socket through which send HTTP connections. If blank, HTTP traffic will be handled by net/http.DefaultTransport.
http_unix_socket:
# What web browser gh should use when opening URLs. If blank, will refer to environment.
browser:lets work in the aliases config
add the next line
persona and work Terminal
aliases:
co: pr checkout
personal: '!cp ~/.config/gh/personal.yml ~/.config/gh/hosts.yml && gh auth status'
work: '!cp ~/.config/gh/work.yml ~/.config/gh/hosts.yml && gh auth status'2.- Create new configs for each one
Example
personal.yml content: Terminal
> cat ~/.config/gh/personal.yml
github.com:
oauth_token: # token not yet generated
git_protocol: ssh
user: yermulnikExample
~/.config/gh/work.yml content: Terminal
> cat ~/.config/gh/work.yml
github.com:
oauth_token: # token not yet generated
git_protocol: ssh
user: george_yermulnik 3.- Now lets copy the token generate in the current account in
host.yml in the line oauth_token and paste in the correctfile
persona.yml or work.yml4.- log-in with the other account and generate a new token copy and the paste in the correct file
2.4k
Related Articles
Discussion
3 commentsShare your thoughts...

