既存のプロジェクトからコードをインポートする

This page describes the methods you can use to import code from existing projects into Bitbucket Data Center and Server. When creating a new repository, you can import code from an existing project into Bitbucket using either the terminal or the web interface.

Bitbucket Cloud を使用している場合、「既存のツールからコードをインポートまたは変換する」ページで詳細を確認してください。

On this page

Web インターフェイスを使用してコードをインポート

Introduced in Bitbucket Server 4.9, you can import code and its version/branching history into Bitbucket from existing Git projects hosted with Bitbucket Cloud, GitHub, GitHub Enterprise, or a standalone Git repository using the web interface.

コードのインポートの開始方法

  1. While viewing a project within Bitbucket click Import repository in the sidebar.
  2. コードのインポート元となるソースを選択し、必要な情報を入力してから、[接続] をクリックします。
    1. For Bitbucket Cloud, include the Username and App password for the account (set at 

      https://bitbucket.org/account/admin/app-passwords)

      to import from, and ensure read access for account, team, project, and repository is enabled.
    2. For GitHub, include the Username and the GitHub personal access token (set at 

      https://github.com/settings/tokens not your GitHub password)

      for the account to import from, and ensure the repo and read:org scopes are enabled.
    3. For GitHub Enterprise, provide the Server URL, Username, and the GitHub personal access token (set at https://github.com/settings/tokens not your GitHub password) for the account to import from, and ensure the repo and read:org scopes are enabled.
    4. 単一の Git リポジトリの場合、クローン URL、ユーザー名、およびパスワード (必要な場合) を提供します。
  3. インポートするリポジトリを選択します。
    1. すべてのリポジトリは、提供されたアカウントが所有するすべてのリポジトリをインポートします。
    2. リポジトリを選択すると、インポートする特定のリポジトリを選択できます。
  4. [インポート] をクリックします。

インポートが完了すると、プロジェクト ページを更新してインポートされたリポジトリを確認できます。


ターミナルを使用してコードをインポート

Import code from an existing project using the terminal by first cloning the repository to your local system and then pushing to an empty Bitbucket repository.

Import an existing, unversioned code project

If you have code on your local machine that is not under source control, you can put it under source control and import it into Bitbucket.

Git がローカルのコンピューターにインストールされていると仮定し、次に:

  1. ローカルで、既存のソースのルートディレクトリを変更します。
  2. ターミナルで次のコマンドを実行し、プロジェクトを初期化します。

    git init
    git add --all
    git commit -m "Initial Commit"
  3. Log into Bitbucket and create a new repository.
  4. 左側のナビゲーション パネルでクローン URL を見つけます (例:  https://username@your.bitbucket.domain:7999 /yourproject/repo.git)。
  5. ターミナルで次のコマンドを実行し、ファイルをリポジトリへプッシュします (URL を適宜変更する):

    git remote add origin https://username@your.bitbucket.domain:7999/yourproject/repo.git 
    git push -u origin master
  6. Done! Your repository is now available in Bitbucket.

Import an existing Git project 

You can import your existing Git repository into an empty repository in Bitbucket. When you do this, Bitbucket maintains your commit history.

  1. 既存の Git ホストからリポジトリをチェック アウトします--bare パラメーターを使用します。

    git clone --bare https://username@bitbucket.org/exampleuser/old-repository.git
  2. Log into Bitbucket and create a new repository (we've called it repo.git in this example).

  3. 左側のナビゲーション パネルでクローン URL を見つけます (例:  https://username@your.bitbucket.domain:7999 /yourproject/repo.git)。

  4. Add Bitbucket as another remote in your local repository:

    cd old-repository
    git remote add bitbucket https://username@your.bitbucket.domain:7999/yourproject/repo.git
  5. Push all branches and tags to the new repository:

    git push --all bitbucket
    git push --tags bitbucket
  6. 一時ローカルリポジトリを削除:

    cd ..
    rm -rf old-repository

既存の Git リポジトリをミラーリングする

You can mirror an existing repository into a repository hosted in Bitbucket.

  1. 既存の Git ホストからリポジトリをチェック アウトします。--mirror パラメーターを使用します。

    git clone --mirror https://username@bitbucket.org/exampleuser/repository-to-mirror.git
  2. Log into Bitbucket and create a new repository (we've called it repo.git in this example).

  3. Locate the clone URL in the nav panel on the left (for example:  https://username@your.bitbucket.domain:7999 /yourproject/repo.git).

  4. Add Bitbucket as another remote in your local repository:

    git remote add bitbucket https://username@your.bitbucket.domain:7999/yourproject/repo.git
  5. Then push all branches and tags to Bitbucket:

    git push --all bitbucket
    git push --tags bitbucket
  6. Use git fetch --prune origin  ('–prune' will remove any branches that no longer exist in the remote) followed by the git push commands from step 5 to update the Bitbucket mirror with new changes from the upstream repository.
最終更新日: 2023 年 2 月 26 日

この内容はお役に立ちましたか?

はい
いいえ
この記事についてのフィードバックを送信する
Powered by Confluence and Scroll Viewport.