Setup a remote Repository using Git and Bitbucket
By: Lukasz Muzyka, On:
This tutorial assumes you have already completed:
In order to be able to leverage git and collaborate with other developers we will need to use "remote" git repository. Remote means that the repository will be saved on the server in the cloud (the internet). We do it because it will serve as a backup and it will make it easier for other developers to collaborate with us. The two most commonly used platforms are Github and Bitbucket. We will use Bitbucket because it allows us to create private repositories for free.
The process of setting up a remote repository for the first time is a little complicated but don't worry. Most of the work you only need to do once.
Step 1: Generate SSH Key
SSH key will be used by bitbucket to securely connect with you. We will also need it to deploy our application to the server. Good instruction for Mac and Linux can be found at this address: https://confluence.atlassian.com/pages/viewpage.action?pageId=270827678. If you're on Windows: https://confluence.atlassian.com/display/BITBUCKET/Set+up+SSH+for+Git
We only need to do it once.
If you're on Mavericks, you can simply run one command and press "ENTER" until you're done (it will use default settings and no password for your key - it's still going to be secure if you don't share your computer)
$ ssh-keygen Generating public/private rsa key pair. Enter file in which to save the key (/Users/lukasz/.ssh/id_rsa): Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /Users/lukasz/.ssh/id_rsa. Your public key has been saved in /Users/lukasz/.ssh/id_rsa.pub. The key fingerprint is: 90:00:0e:9d:d0:ae:b4:76:30:c8:e1:42:e2:e5:40:76 lukasz@lukaszs-air The key's randomart image is: +--[ RSA 2048]----+ |+*.E. | |o*=. . . | |B.* o | |oB.. . | |o.+ S | |.o . | |. . | | | | | +-----------------+ #now you can copy to clipboard. $ pbcopy < ~/.ssh/id_rsa.pub #it now sits in your clipboard so you can paste it wherever you want.
Step 2: Register Bitbucket Account
Go to https://bitbucket.org and create an account.
*Note: if you are in China, make sure to turn off your VPN when creating your account.
After you confirm your account head to the account settings.
Go to SSH Keys and add new key for the computer you're currently working on. If in doubt check the video above.
Step 3: Push to remote repository
All the steps above you only need to do once. Steps below you will do for every single application when you're getting started.
Let's create our first repository.
Once we give it a name click the option "I have an existing project to push up". It will give the instructions how to connect the remote repository and make the initial push.
If this is not your first run, make sure you initialize new git repository:
$ git init $ git add . $ git commit -m "initial commit"
$ git remote add origin email@example.com:YOURLOGIN/NAMEofTHErepo.git $ git push -u origin --all
Now every time you want to synchronize your local and remote repositories you run the code:
$ git push
You can login to comment