Manage unmerged branches

Bitbucket Cloud tracks unmerged branches in the Feature branches view. You can use this view to manage your development process by doing any of the following:

The examples on this page use the commitpractice repository.  You can fork commitpractice to your own account to practice on.

List feature branches

A user must push a branch to the Bitbucket remote repository for it to appear as a feature branch. Feature branches lists only unmerged branches. To list the feature branches, log into Bitbucket do the following:

  1. Navigate to your repository.

  2. Select the Commits context from the navigation bar.

  3. Click Show all.

    The displays includes information about the branch in tags next to the date. In the preceding figure you can see the new-feature branch listed. You can also see that there was another branch fix-issue-1 which was recently merged into the main branch making the new-feature branch one commit behind.

Compare a feature branch to the main line

You can use the Compare function to see differences between code lines.  This function allows you to see individual files and the changes within those files.  Try a comparison now:

  1. Navigate to the public commitpractice repository.

  2. Click + in the global sidebar and select Compare tags or branches under Get to work.

  3. Look for the marysfeature branch.

  4. Press the Compare button on this branch. Change the comparison fields if you like.  

    By default, Bitbucket compares the branch to the tip of the mainline. It shows you the changes on the branch that are not on the source. To see the changes on the main branch that are not on the feature branch, you can swap the branches by clicking change destination and change source.

Sync a branch to the mainline

If a feature branch is behind the current branch, you can sync (merge) the branch with the mainline. You sync a branch, for example, to catch your branch up to all the latest changes on the mainline. Using your commitpractice fork, go ahead and try syncing:

  1. From the sidebar, click Branches.

  2. Locate the meritOrder-feature branch.

  3. From the Commits tab, click Sync now.
    Bitbucket tries to automatically merge for you but only performs primitive merges. Where it detects any conflicts, it asks you to manually resolve these conflicts locally. Bitbucket tells you that there are conflicts.  

  4. Click Close from the Sync branch dialog.

  5. To view the conflicts, click the Diff tab.

  6. Click the Merge button.

    These are the minimum commands you would need to run on your local machine; you may need to do more to merge your files.   

  7. Merge the files on your local machine.
    In this case, I cloned the fork to my local machine and ran the following commands:

    1. Checkout the branch: hg checkout meritOrder-feature

    2. Verify I am on the meritOrder-feature branch: hg branch

    3. As recommend by the Merge changes dialog: hg update meritOrder-feature

    4. As recommend by the Merge changes dialog. Launches my local merge tool, Kdiff, to do the merge: hg merge 6f2745a5694a

    5. Commit the changes: hg commit -m "syncing to main"

    6. Push to Bitbucket: hg push

  8. Press Close.

  9. Push the merged meritOrder-feature back to Bitbucket.
    When you view the new feature branch, you'll find it is no longer "behind" the tip.

Close or delete a branch

When you close or delete a branch, you lose all the unmerged changes on that branch. The branch also no longer appears under the Source list of Branches. You would close an unmerged branch, if for example, the branch represented some experimental testing that failed for which you no longer needed the work.  To close a branch:

  1. From the sidebar, click Branches.

  2. Locate the meritOrder-feature branch.

  3. Click the More button in the top right.

  4. Choose Delete branch.
    Bitbucket displays a confirmation dialog. 

  5. Press Confirm.
    Bitbucket closes the branch, and it no longer appears in your remote repository.

Last modified on Jun 8, 2021
Cached at 4:12 AM on Oct 21, 2021 |

Additional Help