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
Click on “Log in” in the top right corner.
Enter your login credentials and click on the “Log in” button and you should get to the BitBucket Dashboard.
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
Now click on “Repositories” in the menu bar with the blue background and click on “Create repository“.
Enter a repository name and select your access level and select Git and your repository type. Click on “Create repository“.
Now you should see the newly created repository overview page. As you can see above.
Click on your Account Picture or Avatar and select “BitBucket settings”
On the left click on “SSH Keys” under the “Security” section.
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.
Now you need to copy the newly created public key. Execute the following command:
Highlight that key, copy it and paste it in the dialog at BitBucket as you can see in the screenshot below.
Click on “Add key” and BitBucket will show you a list of SSH Keys as you can see in the screenshot below.
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.
cd /path/to/your/project git remote add origin ssh://firstname.lastname@example.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.
The very first time you have to confirm your action and sequential tasks won’t ask you for confirmation.
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
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! 😉