It’s incredibly boring having to do a gh auth login every time you want to use a different account. Today we’re going to learn how to solve that by using an extension which allows us to create multiple profiles and switch between them based on the current directory. To do so, the steps are really simple:
Install the extension
gh extension install gabe565/gh-profile
Create your first profile
gh profile create [NAME]
Login as you usually do
gh auth login
Now, you have created a profile with an associated github account. You can create other ones too by following the following the steps 2 and 3 above.
If you want to switch between multiple profiles you can use
gh profile switch [NAME]
That’s better, but I promised you we were going to be able to use different profiles based on the current directory. In order to achieve it, follow these steps:
Install and setup direnv following their official tutorial: https://direnv.net/docs/installation.html
Whenever you want to set a profile for the current repo, use the -l option:
gh profile switch [NAME] -l
Done. Now whenever you use your terminal on the current directory, is going to be using that specific github profile. No need to keep switching anymore!