Multiple Github Accounts
If you have multiple Github accounts and you want to push your code to any one of those, follow the following steps.
Create SSH keys for each email
ssh-keygen -t ed25519 -C "user1@gmail.com"
# when prompted, write ~/.ssh/id_ed25519_user1
# leave passphrase empty
ssh-keygen -t ed25519 -C "user2@gmail.com"
# when prompted, write ~/.ssh/id_ed25519_user2
# leave passphrase empty
ssh-add ~/.ssh/id_ed25519_user1
ssh-add ~/.ssh/id_ed25519_user2
Create the file called config
and save it in ~/.ssh/
The contents of the config
file are:
Host github-user1
HostName github.com
IdentityFile ~/.ssh/id_ed25519_user1
User git
IdentitiesOnly yes
Host github-user2
HostName github.com
IdentityFile ~/.ssh/id_ed25519_user2
User git
IdentitiesOnly yes
Create your repositry by logging to github.com in your browser
Assume that the name of the new repo is repo1
Push your files
In your local folder with the files present, execute the following commands
git init
git config user.name "user1"
git config user.email "user1@gmail.com"
git add .
git commit -m "My Files"
git remote add origin git@github-user1:user1/repo1
git push -u origin main