Skip to content

Instantly share code, notes, and snippets.

@eru123
Created August 24, 2023 07:30
Show Gist options
  • Save eru123/f7a1c074232f7ca32b45d6bc8efe777a to your computer and use it in GitHub Desktop.
Save eru123/f7a1c074232f7ca32b45d6bc8efe777a to your computer and use it in GitHub Desktop.
@ECHO OFF
setlocal enabledelayedexpansion
@REM store users in a variable, manually
@REM user 1
set user[0]=<github username>
set email[0]=<your email>
set pass[0]=<github token>
set signkey[0]=<gpg token if exists>
set gpgsign[0]=true
@REM user 2
set user[1]=<github username>
set email[1]=<your email>
set pass[1]=<github token>
set signkey[1]=<gpg token if exists>
set gpgsign[1]=false
@REM get arguments
set su=%1
@REM is the argument a number?
set /a isnum=%su%+0
@REM if it is not a number, then it is a username, find the index
if %isnum%==0 (
@rem loop though user list
for /l %%a in (0,1,1) do (
@rem if the user is found, then exit the loop
if !user[%%a]!==%su% (
set su=%%a
goto login
)
)
)
:login
@REM set credential manager to store credentials
git config --global credential.helper store
@REM login as new user
git config --global user.name !user[%su%]!
git config --global user.email !email[%su%]!
git config --global user.signingkey !signkey[%su%]!
git config --global commit.gpgsign !gpgsign[%su%]!
git config --global credential.helper store
@REM login to github
echo Logging in as !user[%su%]!
echo "protocol=https" > %userprofile%\.git-credentials
echo "host=github.com" >> %userprofile%\.git-credentials
echo "username=!user[%su%]!" >> %userprofile%\.git-credentials
echo "password=!pass[%su%]!" >> %userprofile%\.git-credentials
echo Switched to !user[%su%]!
git config --list --global
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment