クローンを行い、新しいブランチに変更を加える
レビュアーを追加してマージ前にコードのレビューと承認を行うことを把握している場合、ブランチを作成する前にリポジトリをクローンすることがあります。そのため、このドキュメントでも、ブランチをセットアップする前にクローン操作について案内します。
Git を使用している場合
ステップ 1. リポジトリをローカル システムにクローンする
作業を開始できるよう、ローカル システム上にクローンしてみましょう。
From the repository, select 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.クローン コマンドをコピーします。
ターミナル ウィンドウで、リポジトリのクローン先のローカル ディレクトリに移動します。
$ cd ~/<path_to_directory>Bitbucket からコピーしたコマンドを貼り付けます。以下に例を示します。
$ git clone https://breezy@bitbucket.org/powerstars/first-impressions.gitCloning 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 から作成しましょう。
Select Branches from the left navigation. You'll see that you already have one branch — your main branch,
master.Select Create a branch in the top right corner.
ブランチを作成したら、ローカル システムからブランチをチェックアウトする必要があります。Bitbucket は、コピーしてコマンド ラインに貼り付けることのできる、次のようなフェッチおよびチェックアウト コマンドを提供します:
$ git fetch && git checkout my-updatesPassword 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 の変更、ファイルの追加、スペース オペラの作曲、単純に質問への回答など、あらゆる変更を行えます。
survey.htmlファイル (または自身で名前を設定したファイル) をテキスト エディタで開きます。任意の変更を加え、ファイルを保存して閉じます。
ターミナル ウィンドウでリポジトリ ディレクトリから移動している場合、リポジトリ ディレクトリに戻ります。
git statusを使用してリポジトリのステータスを表示します。変更したsurvey.htmlファイルが表示されます。他のファイルを追加または変更していた場合は、それらも表示されます。$ git statusOn 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")git add <filename>を使用して変更をローカルに追加します:$ git add survey.htmlgit commit -m "your commit message"を使用して変更をローカルにコミットします。$ git commit -m "Answered questions" [my-updates 7506040] Answered questions 1 file changed, 3 insertions(+), 3 deletions(-)「
git push origin <branch_name>」と入力して変更を Bitbucket のブランチにプッシュし、パスワードを入力して変更のプッシュを完了します。$ git push origin my-updatesPassword 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.From Bitbucket, select the Source page of your repository. You should see both branches in the dropdown. Any other commits you make to
my-updateswill also appear on that branch.
Sourcetree を使用している場合
ステップ 1. リポジトリをローカル システムにクローンする
作業を開始できるよう、ローカル システム上にクローンしてみましょう。
From the repository, select the Clone button in the top right.
Select the Clone in Sourcetree button.
[新規クローン] ウィンドウで [宛先パス] を
<path_to_repo_directory>/first-impressions/に更新します。
4. Select the Clone button.
ステップ 2. ブランチを作成してローカルにプルする
リポジトリのセットアップが完了したので、次の手順に進みます。ブランチは Bitbucket のみの概念ではないため、ローカルでも作成することができます。ただし、このチュートリアルでは、ブランチを Bitbucket から作成します。
Select Branches from the left navigation. You'll see that you already have one branch — your main branch.
Select Create a branch in the top right corner.
Enter a Branch name and select Create. If you aren't sure what to name your branch, go with something like my-updates.
After you create a branch, you need to check it out from your local system. To do so, select the Check out in Sourcetree button.
From the Checkout Existing dialog in Sourcetree, select Checkout.
Bitbucket のブランチを取得してローカル システムにチェック アウトすることができました。これにより、この個別のコード行で作業やプッシュを行うことができます。
ステップ 3. ブランチに変更を加える
次に、リポジトリに変更を加えます。ファイルのメンションと同様、好きなように変更することができます。CSS の変更、ファイルの追加、スペース オペラの作曲、単純に質問への回答など、あらゆる変更を行えます。
From the repository in Sourcetree, select the Show in Finder button.
survey.htmlファイル (または自身で名前を設定したファイル) をテキスト エディタで開きます。任意の変更を加え、ファイルを保存して閉じます。
Sourcetree を開くと、リポジトリに未コミットの変更が表示されていることがわかります。
ファイルをステージング領域に追加します。
[未コミットの変更] 行を選択します。
[ステージ化されていないファイル] リストで、
survey.htmlファイル (および変更がコミットされていないその他のファイル) の横のチェックマークをチェックします。From the Confirm Stage? dialog, select OK.
Select the Commit button at the top to commit the file.
表示されたスペースにコミット メッセージを入力します (例: 回答済みの質問)。
Select the Commit button under the message box. When you switch back to the view, you see that the file has been committed but not pushed to the Bitbucket repository.
From Sourcetree, select the Push button to push your committed changes.
From the dialog that appears, select OK to push your branch with the commit to Bitbucket.
From Bitbucket, select the Source page of your repository. You should see both branches in the dropdown. Any other commits you make to
my-updateswill also appear on that branch.
この内容はお役に立ちましたか?