Skip to content

Instantly share code, notes, and snippets.

@chandrahasan1
Forked from rosswd/multi-git-win.md
Last active August 29, 2015 14:21
Show Gist options
  • Select an option

  • Save chandrahasan1/9cfbdc49c79b3664b329 to your computer and use it in GitHub Desktop.

Select an option

Save chandrahasan1/9cfbdc49c79b3664b329 to your computer and use it in GitHub Desktop.

Setting up a seperate Github and a bitbucket account

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

Setting up github and bitbucket on the same computer

Github will be the main account and bitbucket the secondary.

Create SSH Keys

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

Attach Keys

Login to remote repo and add ssh key:

pbcopy < ~/.ssh/id_rsa.pub
pbcopy < ~/.ssh/id_rsa_bb.pub

Paste into text area under ssh settings in your github or bitbucket account. Also give the ssh key a title like Ross' Laptop.

Create Config file

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_bb

Add the identity to SSH:

ssh-add ~/.ssh/id_rsa
ssh-add ~/.ssh/id_rsa_bb

Enter passphrase when prompted.

Check keys were added:

ssh-add -l

Check that repo recognizes keys:

ssh -T gh
ssh -T bb

Test repositories

Github (default)

Create 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 master

Add some text to readme on github.com, then:

git fetch origin master
git diff master origin/master
git merge origin/master
git push origin master

Bitbucket (secondary)

Create a repo online called testbucket

mkdir ~/testbucket
cd ~/testbucket
touch readme.md
git init

This 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 master

Add 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment