Checkout a branch into a local repository

When working in your local repository, you may want to checkout and work on branch code rather than the main code line.  This page describes how to do this.  Just as with the main code line, when you push branch code to Bitbucket Cloud, it tracks that branch for you.  To see which branches you or others on your team pushed, use the branch list on your repo:

 

Branching is an advanced technique. The information on this page is not a definitive guide for either Git or Mercurial; It merely provides a pointer to help you understand how Bitbucket supports branches. If you plan to use branches a lot or want to know more, we recommend you learn more by visiting a site or buying a book devoted to the DVCS you are using (Git or Mercurial).

Ask Bitbucket for your checkout command

When you checkout a branch, you should already have a local clone of the parent repository. The Bitbucket interface gives you the basic command for checking out a branch. If you're using Sourcetree, Bitbucket gives you a single button checkout.   

  1. Go to the repository's Source tab.
  2. Use the dropdown to filter for the branch you want to checkout.
  3. Press the   (clone) button.  
    The system displays the appropriate clone command for your DVCS or choose Clone in Sourcetree if Sourcetree is installed. 
  4. Open a terminal on your local machine.
  5. Change to the root directory of your repository clone.
  6. At the command line, enter the command copied from Bitbucket and press ENTER.

Using Git to checkout a branch on the command line

On your local system, make sure you have a local repository cloned from the remote repository. Then, do the following:

  1. Change to the root of the local repository.

    $ cd mytestproject
  2. List all your branches:

    $ git branch -a

    You should see something similar to the following:

     

    * master
      remotes/origin/HEAD -> origin/master
      remotes/origin/feature
      remotes/origin/master

    Notice that it lists both the branches that are local and the remote branches  on Bitbucket. Using the list as reference, choose the branch you want to checkout.  In this example, the feature branch is the branch.

  3. Checkout the branch you want to use.

    $ git checkout feature
  4. Confirm you are now working on that branch:

    $ git branch

    You should see something similar to the following:

    $ git branch
    * feature
      master

Going forward, all your Git commands apply to the branch.  When you push the changes to your remote Bitbucket repository, those changes apply to the repository's branch.

Using Mercurial to checkout a branch on the command line

On your local system, make sure you have a local repository cloned from the remote repository. Then, do the following:

  1. リポジトリのルートに変更します。

    $ cd mytestproject
  2. List all your branches:

    $ hg branches

    You should see something similar to the following:

    niptuck                        2:f33855c6564f
    feature                        1:8928355fee43 (inactive)
    default                        0:9a972e4b5a97 (inactive)

    Notice that it lists both the branches that are local and the remote branches  on Bitbucket. Using the list as reference, choose the branch you want to use.  In this example, the feature branch is the branch.

  3. Switch to the branch you want to use.

     

    $ hg update feature
  4. Confirm you are now working on that branch:

    $ hg branch

    You should see something similar to the following:

    feature

Going forward, all your Hg commands apply to the branch.  When you push the changes to your remote Bitbucket repository, those changes apply to the repository's branch.

最終更新日: 2016 年 12 月 16 日

この翻訳に満足しましたか?

はい
いいえ
この記事についてのフィードバックを送信する

お探しの情報が見つかりませんか?

コミュニティへの質問

Powered by Confluence and Scroll Viewport.