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 system lists any branches not already merged into the mainline:

    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 master 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. Select the More>Compare... >Compare if you have the sidebar collapsed) from the actions section in the navigation bar.
  3. Look for the marysfeature branch.
  4. Press the Compare button on this branch.Change the comparison fields if you like.
    The system displays the following: 

    By default, the system 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 master that are not on the branch, you need to Swap the source and destination. You can compare two branches on the same repository. You can switch the source an destination. 

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 would 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. Go to the Feature branches view.
  2. Locate the meritOrder-feature branch.
  3. Select the  (cog) drop down.
  4. Choose Sync branch.
    The system confirms your choice. 
  5. Press Sync.
    Bitbucket tries to automatically merge for you. Bitbucket only performs primitive merges. Where it detects any conflicts, it asks you to manually resolve these conflicts locally. The system tells you that there are conflicts.  
  6. Click View the conflicts.
    The system takes you to the Compare dialog. On the Compare dialog, you will see a   (warning) next to the Create pull request and Merge buttons. 
  7. Click the Merge button.
    Bitbucket displays some commands that you can use to merge and sync the branch locally:

    These are the minimum commands you would need to run on your local machine; you may need to do more to merge your files.   
  8. Merge the files on your local machine.
    In this case, I cloned the fork to my local machine and ran the following commands:

    Command Description
    hg checkout meritOrder-feature
    Checkout the branch.
    hg branch
    Verify I am on the meritOrder-feature branch.
    hg update meritOrder-feature
    As recommend by the Merge changes dialog.
    hg merge 6f2745a5694a 
    As recommend by the Merge changes dialog. Launches my local merge tool, Kdiff, to do the merge.
    hg commit -m "syncing to master"
    Commit the changes.
    hg push 
    Push to Bitbucket.
  9. Press Close.
  10. 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 a branch

When you close 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. Go to the Feature branches view.
  2. Locate the meritOrder-feature branch.
  3. Select the  (cog) drop down.
  4. Choose Close branch.
    The system confirms your choice. 
  5. Press OK.
    Bitbucket close the branch; it no longer appears in your remote repository.

Was this helpful?

Thanks for your feedback!

Why was this unhelpful?

Have a question about this article?

See questions about this article

Powered by Confluence and Scroll Viewport