Push versioned code to an empty repository

You can upload an existing repository to a empty project in Bitbucket. When you do this, Bitbucket maintains your commit history.

If you don't yet have a Bitbucket repository, create a repository there first.

Pushing a Git project

This kind of push overwrites the contents of the Bitbucket repository. You should use it with great caution.

  1. From the command line, verify your SSH key is working.

    $ ssh -T git@bitbucket.org
    conq: logged in as tutorials.

    You can use git or hg to connect to Bitbucket. Shell access is disabled.

    The message should report you are logged in as your Bitbucket account. In this example, the ssh key was on the tutorials account. If you don't get this message, stop and troubleshoot your SSH connection to Bitbucket. (See Use the SSH protocol with Bitbucket Cloud for information about doing this.)

  2. Navigate to the root directory of the repository you want to push.

    $ cd ~/repos/<repo_name>
  3. Push the local repository up to Bitbucket.

    $ git push --mirror git@bitbucket.org:<account_name>/<repo_name>
Push Several Branches at Once

If you want, you can push several branches at once to your Bitbucket repository. To do this, do the following:

  1. Checkout each branch to your local repository from your existing Git host.
  2. List all the branches to make sure you have what you want:

    $ git branch -a
  3. Make sure the remote origin in your local repository points to Bitbucket.
    For example, if you are using ssh with Bitbucket, you would use the following:

  4. Then push all the branches to Bitbucket:

    $ git push -u origin --all

Pushing a Mercurial project

This kind of push overwrites the contents of the Bitbucket repository. You should use it with great caution.

  1. From your Mercurial repository on your local system, open the .hg subdirectory.

    Files that start with a . (period) are hidden files in Mac OSX. By default, the Finder does not show these files. To reveal hidden files, enter the following command into the terminal:

    $ defaults write com.apple.finder AppleShowAllFiles YES

    To hide them files once again, enter the following command:

    $ defaults write com.apple.finder AppleShowAllFiles NO
  2. Open the hgrc file.
  3. Edit the default value by changing it to the address of the empty repository you created in Bitbucket. The top of your file will look similar to the following:

    [paths]
    default = ssh://hg@bitbucket.org/<account_name>/<repo_name>
  4. Save and close the file.
  5. Push the repository:

    $ hg push

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