If you work for a company and code on the side you may need to manage multiple Github accounts from the same device.
Here's how to push from two different Github accounts locally
Step 1) Create SSH keys
For each SSH key pairs:
run ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
You'll be prompted: "Enter a file in which to save the key" so make sure to use a unique name like "company" or "personal".
Step 2) Add public key to Github
Follow these steps.
Step 3) Create an ssh config file
cd ~/.ssh
touch config
Enter something like this making sure to save after:
#personal account
Host github.com-personal
HostName github.com
User git
IdentityFile ~/.ssh/personal
IdentitiesOnly yes
#user2 account
Host github.com-company
HostName github.com
User git
IdentityFile ~/.ssh/company
IdentitiesOnly yes
Step 4) Clone Repo
git clone git@github.com-company:REPOSITORY_NAME.git
Step 5) Edit config
You'll need to do this for each repo
Open up local git config using git config --local -e and add:
[user]
name = company
email = name@company.com
type :wq
and enter to save and quit
Step 6) Confirm your remote url
git remote set-url origin git@github-comcompany:REPOSITORY_NAME.git
Step 7) Git add commit and push
Now you can git actions (pull/push/fetch...etc) all you like!
Resources:
https://www.youtube.com/watch?v=R5yS23LKr04
https://gist.github.com/Jonalogy/54091c98946cfe4f8cdab2bea79430f9
Top comments (0)