Check out a branch

When working in your local repository, you may want to checkout and work on branch code rather than the main code line. 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 workspace pushed, see the Branches list in your repository.

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. In the repository's Branches, click the branch you want to checkout.

  2. Press the Check out button to display the appropriate check out command.

  3. Copy the command (or choose Check out in Sourcetree if you'd rather use Sourcetree).

  4. Open the terminal on your local machine and change to the root directory of your repository.

  5. At the command line, enter the copied command from Bitbucket and press ENTER.

Using Git to checkout a branch on the command line

For the purposes of these steps, <feature_branch> will refer to the name of your branch.

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 <repo_name>

  2. List all your branches:

    $ git branch -a

    You should see something similar to the following:

    * main   <feature_branch>

    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_branch>

  4. Confirm you are now working on that branch:

    $ git branch

    You should see something similar to the following:

    $ git branch
    * <feature_branch>

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.


Still need help?

The Atlassian Community is here for you.