GIT and Remote Repository at BitBucket

Good Day my dear Linux Yogi’s,

in this illustration I am going to demonstrate how to configure your local repository to be able to push to a remote repository at BitBucket. Please read the previous article: Version Control with GIT  and then proceed with this article. I also assume you already have created an account with BitBucket.

Follow along as we set up a new repository at BitBucket, generate SSH Key and finally push our local repository to BitBucket.

Lets get started. Open up your web browser and go to https://bitbucket.org

BitBucket Website
BitBucket Website

Click on “Log in” in the top right corner.

BitBucket login

BitBucket login

Enter your login credentials and click on the “Log in” button and you should get to the BitBucket Dashboard.

BitBucket Dashboard overview
BitBucket Dashboard overview

Click on the “Repository” link right next to the “Overview” link and you should see a list of repositories if you have already set some up.

BitBucket Repository list

BitBucket Repository list

Now click on “Repositories” in the menu bar with the blue background and click on “Create repository“.

BitBucket create repository
BitBucket create repository
BitBucket create repository form
BitBucket create repository form

Enter a repository name and select your access level and select Git and your repository type. Click on “Create repository“.

BitBucket new repository overview
BitBucket new repository overview

Now you should see the newly created repository overview page. As you can see above.

BitBucket Settings
BitBucket Settings

 

 

 

 

 

 

 

 

 

Click on your Account Picture or Avatar and select “BitBucket settings

BitBucket SSH Keys
BitBucket SSH Keys

 

 

 

 

 

 

On the left click on “SSH Keys” under the “Security” section.

BitBucket Add SSH Keys
BitBucket Add SSH Keys

Click on “Add key” and a new dialog opens up. Leave it and open up a terminal. You need to generate a SSH Public Key. Enter the following command:

ssh-keygen -t rsa -b 2048

The option -t rsa determines the encryption key and -b 2048 specifies the strength of the key. Those are good values to start with.

Generate Key on Linux Workstation
Generate Key on Linux Workstation

Now you need to copy the newly created public key. Execute the following command:

cat /home/<your_username_here>/.ssh/id_rsa.pub
copy ssh public key
copy ssh public key

Highlight that key, copy it and paste it in the dialog at BitBucket as you can see in the screenshot below.

Paste Public Key into BitBucket
Paste Public Key into BitBucket

Click on “Add key” and BitBucket will show you a list of SSH Keys as you can see in the screenshot below.

List of SSH Keys
List of SSH Keys

Now when you go back to your newly created repository towards the bottom there as some instructions. Click on the link “I have an existing project” and follow those instructions.

BitBucket instructions to add remote
BitBucket instructions to add remote
cd /path/to/your/project

git remote add origin ssh://git@bitbucket.org/<username_here>/sample_app.git

git push -u origin master

Make sure you adjust the above information matching your setup. The second line adds the remote repository and the third line pushes it upstream to the origin which is the remote repository from the master which is your local repository.

Add remote repo and first push
Add remote repo and first push

The very first time you have to confirm your action and sequential tasks won’t ask you for confirmation.

results of first remote push
results of first remote push

Make a change to one file for example the README.md, save it and execute the following commands:

git add -A

git commit -m "Message here"

git push -u origin master
made change and commit and push to remote repo
made change and commit and push to remote repo

As you can see in the screenshot it did not ask for confirmation so everything is working the way it supposed to.

I hope you liked this article and in the next one I will illustrate how to version control your servers etc directory with etckeeper, git and bitbucket.

Until then, NAMASTE my friends! 😉