Get started with Bitbucket Cloud
New to Bitbucket Cloud? Check out our get started guides for new users.
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).
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.
In the repository's Branches, click the branch you want to checkout.
Press the Check out button to display the appropriate check out command.
Copy the command (or choose Check out in Sourcetree if you'd rather use Sourcetree).
Open the terminal on your local machine and change to the root directory of your repository.
At the command line, enter the copied command from Bitbucket and press ENTER.
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:
Change to the root of the local repository.
$ cd <repo_name>
List all your branches:
$ git branch -a
You should see something similar to the following:
* main <feature_branch>
remotes/origin/<feature_branch>
remotes/origin/main
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.
Checkout the branch you want to use.
$ git checkout <feature_branch>
Confirm you are now working on that branch:
$ git branch
You should see something similar to the following:
$ git branch
* <feature_branch>
main
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.
Was this helpful?