Nikos Papandreou
  • Home
  • Profile
  • Programming
    • Anonymous Outlook
    • Autorun Generator
    • Compiler
  • Blog

Introduction to Bitbucket

15/10/2013

3 Comments

 
Bitbucket is a source code hosting service. It allows you to store your projects' source code and  share it with others or keep it private. Bitbucket projects can be hosted in either Mercurial or Git revision control systems.
In this example, I will try to explain how to start a project using Mercurial revision control software and Ubuntu.

Sign up to Bitbucket

Create a repository

Install mercurial

Open a terminal
sudo apt-get install mercurial

Add your credentials to your machine

Create the file ~/.hgrc in your home directory with the following contents.
[ui]
username = Name Surname <yourmail@domain.com>

ssh way (Optional)

Open a terminal and generate your ssh key.
ssh-keygen
Install xclp.
sudo apt-get install xclip
Copy ssh key to clipboard.
xclip -sel clip < ~/.ssh/id_rsa.pub
Go to Bitbucket -> Manage account -> SSH keys -> Add key and paste your ssh key.

Clone your empty newproject

hg clone ssh://hg@bitbucket.org/accountname/newproject

Create a file and mark the commit

echo "# This is my README" >> README.md
hg addremove
hg commit -m "First commit. Adding a README."

Push changes

hg push https://accountname@bitbucket.org/accountname/newproject

ssh way (Optional)

hg push ssh://hg@bitbucket.org/accountname/newproject

Ignore files from push

To ignore files from the push, create .hgignore file in your projects root directory, with the following contents.
# use glob syntax.
syntax: glob
.hgignore
private_file.php
*~
In this way, you protect private_file.php, all backup files (ending with ~) and .hgignore file as well.

Strip accidental commits

It is a common mistake to push a commit that contained personal files.
To delete such a commit visit the repository page in Bitbucket.
Go to Commits and copy the commit hash.
Then go to repository Administration -> Strip changesets -> Paste the hash -> Preview and Confirm Strip.
Finally, go to Commits to verify it's removal.

Strip commit locally

To enable strip, add the following lines to ~/.hgrc
[extensions]
hgext.mq =
Then, in a terminal at your projects root directory, enter the following command with the commit_hash you want to remove.
hg strip -r commit_hash
3 Comments
MakisH
23/11/2013 09:22:40

Good job! Is there a graphical way to deal with the most common steps? I mean from the "Clone your empty newproject" and below.

Reply
Nikos Papandreou
23/11/2013 09:59:53

There are two approaches to the subject.

The first one is to download a zip archive by clicking the download link in the projects main page.

The other is to install mercurial (see post for instructions) and then use the terminal:
hg clone https://bitbucket.org/accountname/newproject

Reply
Isa link
17/1/2021 22:08:29

Apprreciate your blog post

Reply



Leave a Reply.

    Categories

    All
    Bitbucket
    Forefront
    Mercurial
    Php
    Sqlite
    Ssh
    Windows

    Archives

    October 2015
    November 2014
    March 2014
    October 2013

    RSS Feed