Skip to content

Instantly share code, notes, and snippets.

@tonycaputome
Forked from k4zek4ge/multiplegit.sh
Created May 28, 2020 09:47
Show Gist options
  • Save tonycaputome/92c21a53a32af280682e19e90433fc60 to your computer and use it in GitHub Desktop.
Save tonycaputome/92c21a53a32af280682e19e90433fc60 to your computer and use it in GitHub Desktop.
[multiple git accounts] #git
ls -al ~/.ssh
#
# generate ssh key
#
ssh-keygen -t rsa -C "email@work_mail.com" -f "id_rsa_work_user1"
#
#Adding the new SSH key to the corresponding GitHub account
#
Copy the public key pbcopy < ~/.ssh/id_rsa.pub and then log in to your personal GitHub account:
1 Go to Settings
2 Select SSH and GPG keys from the menu to the left.
3 Click on New SSH key, provide a suitable title, and paste the key in the box below
4 Click Add key — and you’re done!
#
#Registering the new SSH Keys with the ssh-agent
#
ssh-add ~/.ssh/id_rsa_work_user1
#
#Creating the SSH config File
#
cd ~/.ssh/
touch config // Creates the file if not exists
code config // Opens the file in VS code, use any editor
# Personal account, - the default config
Host github.com
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa
# Work account-1
Host github.com-work_user1
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa_work_user1
#
#Clone repo
#
git clone git@github.com-work_user1:work_user1/repo_name.git
#
#For Locally Existing Repositories
#
If we have the repository already cloned:
List the Git remote of the repository, git remote -v
Check whether the URL matches our GitHub host to be used, or else update the remote origin URL.
git remote set-url origin git@github.com-worker_user1:worker_user1/repo_name.git
Ensure the string between @ and : matches the Host we have given in the SSH config.
#
#If you are creating a new repository on local:
#git init
Initialize Git in the project folder git init.
Create the new repository in the GitHub account and then add it as the Git remote to the local repository.
git remote add origin git@github.com-work_user1:work_user1/repo_name.git
Ensure the string between @ and : matches the Host we have given in the SSH config.
Push the initial commit to the GitHub repository:
git add .
git commit -m "Initial commit"
git push -u origin master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment