Add unversioned code to a repository

Still need help?

The Atlassian Community is here for you.

Ask the community

If you have code on your local machine that is not under source control, you can prepare it by putting your code into a Git or Mercurial repository locally. From there, you push it to Bitbucket.

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

Add to a Git repository

  1. From your terminal, change to the root directory of your existing code.
  2. Initialize the directory under source control from the following command:

    $ git init
  3. Add the existing files to the repository you have initialized:

    $ git add .
  4. Commit the files:

    $ git commit -m "initial commit of full repository"

    On macOS, you can use single quotes or double quotes around the comment message. On Windows, you must use double quotes.

  5. Connect your new local Git repository to the remote repository on Bitbucket. To do so, enter git remote add origin with the remote URL:

    $ git remote add origin <bitbucket_URL>

    You can find the URL next to the git clone command for the repository:

  6. Push all the code in your local repo to Bitbucket with the following command:

    $ git push -u origin --all

Add to a Mercurial repository

  1. From your terminal, change to the root directory of your existing code.
  2. Initialize the directory under source control from the following command:

    $ hg init
  3. Add the existing files to the repository you have initialized:

    $ hg add
  4. Commit the files:

    $ hg commit -m "initial commit of full repository"

    On macOS, you can use single quotes or double quotes around the comment message. On Windows, you must use double quotes.

  5. Connect your new local Mercurial repository to the remote repository and push all your code to Bitbucket at the same time. To do so, enter hg push with the remote URL:

    $ hg push <bitbucket_URL>

    You can find the URL next to the hg clone command for the repository:

  6. Now that you've got your repository on Bitbucket, you need to add the remote URL to the repository's config file so that you'll be able to push and pull from the repository in the future.
    1. (macOS) Make sure you can see hidden files. Files that start with a . (period) are hidden by default in macOS.

      To reveal hidden files

      Enter the command for revealing hidden files followed by a command to close and reopen your Finder windows:

      $ defaults write com.apple.finder AppleShowAllFiles -boolean true
      $ killall Finder
    2. Navigate to the repository locally. You should see a .hg directory in the repository directory.

    3. Download this hgrc file and add it to the .hg directory: hgrc

    4. Open the hgrc file and replace ---Bitbucket URL--- with the same URL you got from the repository in step 5.

    5. Save and close the hgrc file.
Last modified on Jun 5, 2018

Was this helpful?

Yes
No
Provide feedback about this article
Powered by Confluence and Scroll Viewport.