Set up Git and Mercurial (Ubuntu Linux)

To use Bitbucket, you need to install a DVCS tool on the computer where you write your code. Typically, this computer is a machine physically close to you like your home or work computer. This is your local machine or system. You also might write or deploy code to a remote machine – for example a lab computer or a server in a data center. You may also need a DVCS tool on that machine too. These instructions refer to the typical case, your local system, but the instructions are the same for both cases.

Bitbucket supports two DVCS tools, Git and Mercurial. These tools run on all modern operating systems.  For Git, Bitbucket supports 1.6.6 or later and Mercurial version 1.7 or later. Mercurial also requires (depends on) the Python programming language. The installation process takes care of making sure you get the correct version of Python.

This documentation shows you how to install on Ubuntu Linux. If you want to install on Microsoft Windows or Mac OSX, we have instructions for that too.

Step 1. Install Git

Ubuntu uses the apt package management system, which provides the command line utility apt-get and optional graphical interfaces, such as Synaptic and Aptitude. We'll use apt-get to install packages, but if you're more comfortable with GUIs, those options are available.

Step 1. Install Git for Linux

  1. Enter the following command to install Git:

    $ sudo apt-get install git
  2. Verify the installation was successful by typing which git at the command line.

    $ which git

Step 2. Update your configuration file

  1. Configure your username using the following command.

    $ git config --global "Emma Paris"
  2. Configure your email address using the following command.

    $ git config --global ""
  3. Configure Git to handle line endings properly. We recommend this setting if you're collaborating on repositories with others who have different operating systems. Without this setting, Bitbucket may consider files as changed even if the actual content doesn't change because each operating system handles line endings differently.

    $ git config --global core.autocrlf input

Step 2. Install Mercurial

Open a terminal window and do the following:

  1. Make sure the universe repository is uncommented in the /etc/apt/sources.list file.
    To view the file, you can enter cat /etc/apt/sources.list at the command line. If the universe repo is uncommented the file contains a section similar to the following (example based on Ubuntu 10.04 Lucid Lynx):

    deb lucid universe
    deb-src lucid universe 
    deb lucid-updates universe
    deb-src lucid-updates universe 
    deb lucid-security universe
    deb-src lucid-security universe 

    If the lines are still commented (have a # prefix), then edit the file and uncomment them.

  2. Make sure you have an updated package list by entering the following at the command line:

    sudo apt-get update
  3. Enter the following command to install Mercurial:

    sudo apt-get install mercurial 
  4. Verify the installation was successful by typing which hg at the command line:

    $ which hg

    Hg is the chemical symbol for Mercury and hg is the command for Mercurial. 

  5. If you don't already have one, create a file named .hgrc  in your ~ (home) directory.
    This file is the Mercurial global configuration file.
  6. Edit  the ~/.hgrc file using your favorite editor.
  7. Specify a username value.
    When you are done, the contents of the .hgrc configuration file look something like this:

    # Name data to appear in commits
    username = Mary Anthony <>
  8. Save and close the file.

Was this helpful?

Thanks for your feedback!

Why was this unhelpful?

Have a question about this article?

See questions about this article

Powered by Confluence and Scroll Viewport