- Install
gh
CLI tool from GitHub CLI
-
Obtain PAT ( Personal access Token):
- Click the profile icon on the top right corner.
- Navigate to developer settings.
- Select Personal Access Tokens and generate a token.
-
Open
.gitconfig
File:Navigate to the
.gitconfig
file inside your Users folder. -
Paste the Following Alias Configuration:
Add the following lines under the
[alias]
section in your.gitconfig
file. Replace placeholders with valid values.[alias] control = "!f() { token='[PAT_Token_One]'; if [ $1 == "[first_trigger_name]" ]; then token='[PAT_Token_One]'; fi; echo $token | gh auth login --with-token; gh auth setup-git; }; f"
Following is an example with dummy values,
[alias] control = "!f() { token='iamtokenone'; if [ $1 == "[work]" ]; then token='iamtokentwo'; fi; echo $token | gh auth login --with-token; gh auth setup-git; }; f"
-
Switching Between GitHub Accounts:
To switch between two GitHub accounts, use the provided alias
control
with a trigger name.git control [trigger_name_1]
Replace
[trigger_name_1]
with your desired trigger name.