This guide assumes:
- git is set up for a github user using https, not ssh
- There is only a known_hosts files in
~/.ssh/ - The computer is running Mac OS 10
Github will be the main account and bitbucket the secondary.
ssh-keygen -t rsa -C "github email"
ssh-keygen -t rsa -C "bitbucket email"Enter passphrase when prompted.
Save keys to:
~/.ssh/id_rsa
~/.ssh/id_rsa_bb
Login to remote repo and add ssh key:
pbcopy < ~/.ssh/id_rsa.pub
pbcopy < ~/.ssh/id_rsa_bb.pubPaste into text area under ssh settings in your github or bitbucket account. Also give the ssh key a title like Ross' Laptop.
I am using macvim, alias mvim, enter your editor here if different:
mvim ~/.ssh/config
#Github (default)
Host gh
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa
#Bitbucket (secondary)
Host bb
HostName bitbucket.org
User git
IdentityFile ~/.ssh/id_rsa_bbssh-add ~/.ssh/id_rsa
ssh-add ~/.ssh/id_rsa_bbEnter passphrase when prompted.
Check keys were added:
ssh-add -l
ssh -T gh
ssh -T bbCreate a repo online called testmulti
mkdir ~/testmulti
cd ~/testmulti
touch readme.md
git init
git add .
git commit -am "first commit"
git remote add origin git@gh:rosswd/testmulti.git
git push origin masterAdd some text to readme on github.com, then:
git fetch origin master
git diff master origin/master
git merge origin/master
git push origin masterCreate a repo online called testbucket
mkdir ~/testbucket
cd ~/testbucket
touch readme.md
git initThis being the secondary account, the username and email have to be overwritten, using secondary account values, at the repo level:
git config user.name "Full Name"
git config user.email "email"This must be done once for every bitbucket repo, it is not needed for github repos because the global is used in that scenario. There may be a cleaner way to do this but right now it works ok.
git add .
git commit -am "first commit"
git remote add origin git@bb:rosswd/testbucket.git
git push origin masterAdd some text to readme on bitbucket.org, then:
git fetch origin master
git diff master origin/master
git merge origin/master
git push origin master