クローンを行い、新しいブランチに変更を加える

このページの内容

お困りですか?

アトラシアン コミュニティをご利用ください。

コミュニティに質問

robotsnoindex
robotsnoindex


When you know that you will be adding reviewers to review and approve your code prior to merging, you’d most likely already have the repository cloned before creating a branch. So that’s what we’re going to do first before you set up your own branch.

Git を使用している場合

ステップ 1. リポジトリをローカル システムにクローンする

作業を開始できるよう、ローカル システム上にクローンしてみましょう。

  1. From the repository, click the Clone button in the top right.
    Bitbucket displays the Clone this repository dialog. By default, the clone dialog sets the protocol to HTTPS or SSH, depending on your settings. As a result, you don't need to change your default protocol.
  2. クローン コマンドをコピーします。
  3. From a terminal window, change into the local directory where you want to clone your repository.
    cd ~/<path_to_directory>
  4. Paste the command you copied from Bitbucket, for example:
    git clone  https://breezy@bitbucket.org/powerstars/first-impressions.git

    Cloning into 'first-impressions'...
    Password for 'https://breezycloud@bitbucket.org': 
    remote: Counting objects: 6, done.
    remote: Compressing objects: 100% (5/5), done.
    remote: Total 6 (delta 1), reused 0 (delta 0)
    Unpacking objects: 100% (6/6), done.

ステップ 2. ブランチを作成してローカルにプルする

リポジトリのセットアップが完了したので、次の手順に進みます。これで、ローカルまたは Bitbucket からブランチを作成できるようになりました。このチュートリアルでは、Bitbucket からブランチを作成します

  1. 左側のナビゲーションから [ブランチ] を選択します。1 つのブランチ (main ブランチである master) が表示されます。
  2. 右上の [ブランチの作成] をクリックします。
  3. After you create a branch, you need to check it out on your local system. Bitbucket provides you with a fetch and checkout command that you can copy and paste into your command line, similar to the following:
    git fetch && git checkout my-updates

    Password for 'https://breezycloud@bitbucket.org': 
    From https://bitbucket.org/planetbreezycloud/first-impressions
            
     * [new branch]      my-updates -> origin/my-updates
    Branch 'my-updates' set up to track remote branch 'my-updates' from 'origin'.
    Switched to a new branch 'my-updates'

ローカルで新しいブランチに切り替えることができました。これにより、この個別のコード行で作業やプッシュを行うことができます。

ステップ 3. ブランチに変更を加える

次に、リポジトリに変更を加えます。ファイルのメンションと同様、好きなように変更することができます。CSS の変更、ファイルの追加、スペース オペラの作曲、単純に質問への回答など、あらゆる変更を行えます。

  1. survey.html ファイル (または自身で名前を設定したファイル) をテキスト エディタで開きます。
  2. 任意の変更を加え、ファイルを保存して閉じます。

  3. ターミナル ウィンドウでリポジトリ ディレクトリから移動している場合、リポジトリ ディレクトリに戻ります。git status を使用してリポジトリのステータスを表示します。変更した survey.html ファイルが表示されます。他のファイルを追加または変更していた場合は、それらも表示されます。

    git status
    On branch my-updates
    Your branch is up-to-date with 'origin/my-updates'.
    Changes not staged for commit:
      (use "git add <file>..." to update what will be committed)
      (use "git checkout -- <file>..." to discard changes in working directory)
            modified:   survey.html
    no changes added to commit (use "git add" and/or "git commit -a")

  4. Add your changes locally with git add <filename>:
    git add survey.html

  5. Commit your changes locally with  git commit -m "your commit message":
    git commit -m "Answered questions"
    [my-updates 7506040] Answered questions
     1 file changed, 3 insertions(+), 3 deletions(-)

  6. Enter git push origin <branch_name> to push the changes to your branch on Bitbucket, and enter your password to finish pushing changes.
    git push origin my-updates

    Password for 'https://breezycloud@bitbucket.org': 

    Counting objects: 3, done.

    Delta compression using up to 8 threads.

    Compressing objects: 100% (3/3), done.

    Writing objects: 100% (3/3), 350 bytes | 350.00 KiB/s, done.

    Total 3 (delta 1), reused 0 (delta 0)

    To https://bitbucket.org/planetbreezycloud/first-impressions.git

       454ccaf..7506040  my-updates -> my-updates

    Branch master set up to track remote branch master from origin.

  7. Bitbucket で、リポジトリの [ソース] ページをクリックします。ドロップダウンに両方のブランチが表示されます。my-updates に対するその他のコミットも、そのブランチに表示されます。

Sourcetree を使用している場合

ステップ 1. リポジトリをローカル システムにクローンする

作業を開始できるよう、ローカル システム上にクローンしてみましょう。

  1. From the repository, click the Clone button in the top right.
  2. [Sourcetree でクローン] ボタンをクリックします。
  3. [新規クローン] ウィンドウから、宛先パス<path_to_repo_directory>/first-impressions/ に更新します。

  4. [クローン] ボタンをクリックします。

ステップ 2. ブランチを作成してローカルにプルする

リポジトリのセットアップが完了したので、次の手順に進みます。ブランチは Bitbucket のみの概念ではないため、ローカルでも作成することができます。ただし、このチュートリアルでは、ブランチを Bitbucket から作成します。

  1. 左側のナビゲーションから [ブランチ] を選択します。1 つのブランチ (main ブランチ) が表示されているはずです。
  2. 右上の [ブランチの作成] をクリックします。
  3. ブランチ名を入力して [作成] をクリックします。ブランチ名が不明な場合、my-updates などとします。
  4. ブランチを作成したら、ローカル システムからチェックアウトする必要があります。これを行うには、[Sourcetree でチェックアウト] ボタンをクリックします。

  5. Sourcetree の [既存のものをチェックアウト] ダイアログから、[チェックアウト] をクリックします。

Bitbucket のブランチを取得してローカル システムにチェック アウトすることができました。これにより、この個別のコード行で作業やプッシュを行うことができます。

ステップ 3. ブランチに変更を加える

次に、リポジトリに変更を加えます。ファイルのメンションと同様、好きなように変更することができます。CSS の変更、ファイルの追加、スペース オペラの作曲、単純に質問への回答など、あらゆる変更を行えます。

  1. Sourcetree のリポジトリから、[Finder で表示] ボタンをクリックします。
  2. survey.html ファイル (または自身で名前を設定したファイル) をテキスト エディタで開きます。
  3. 任意の変更を加え、ファイルを保存して閉じます。

  4. Sourcetree を開くと、リポジトリに未コミットの変更が表示されていることがわかります。
  5. (Git のみ) ファイルをステージング領域に追加します。
    1. [未コミットの変更] 行を選択します。
    2. From the Unstaged files list, place a checkmark next to the survey.html file (and any other files with uncommitted changes).
    3. [ステージの確認] ダイアログで、[OK] をクリックします。
  6. 一番上の コミット ボタンをクリックしてファイルをコミットします。
  7. 表示されたスペースにコミット メッセージを入力します (例: 回答済みの質問)。
  8. メッセージ ボックスの下の [コミット] ボタンをクリックします。ビューに切り替えると、ファイルはコミットされているが、Bitbucket リポジトリにはプッシュされていないことがわかります。
  9. Sourcetree で、[プッシュ] ボタンをクリックしてコミットされた変更をプッシュします。
  10. 表示されたダイアログ ボックスで [OK] をクリックして、コミットされたブランチを Bitbucket にプッシュします。

  11. Bitbucket で、リポジトリの [ソース] ページをクリックします。ドロップダウンに両方のブランチが表示されます。my-updates に対するその他のコミットも、そのブランチに表示されます。


次へ

Last modified on Mar 15, 2022

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

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