Use Sourcetree branches to merge an update

After looking through the Intergalactic Mall Magazine, you see a pair of speakers that you really want for the space station. They are big enough to produce a good amount of sound and soft enough that the lack of gravity won't cause them to crash. The only problem is that they are pretty pricey, and you need approval before you can officially add them to your list of supplies.

In the meantime, create a feature branch so that you can update the supply to your request list while you wait. Then when you have approval, you just merge the requests file from the feature branch into the main branch.

Branches are most powerful when you're working collectively with your colleagues. You can work on your own part of a project from your own branch, pull updates from Bitbucket, and then merge all your work into the main branch when it's ready. Our documentation includes more explanation of why you would want to use branches.

Step 1. Create a branch and make a change

Let's create a branch so that you can list the speakers in your supply requests file.

  1. From Sourcetree, click the Branch button.

  2. From the New Branch or Create a new branch field, enter wish-list for the name of your branch.

  3. Click Create Branch or OK.

  4. From Sourcetree, click the Show in Finder button. The directory on your system opens.

  5. From the directory folder, open the supplyrequest file with a text editor.

  6. Making a change to the file by adding the following item to the list of supplies:

    <li>anti-gravity speakers</li>

  7. Save the file.

  8. Open the view in Sourcetree and notice that your repository now has uncommitted changes.

    From here, everything you do is the same as you did when you added the supplyrequest file and initially committed it.

  9. If you have a Git repository, make supplyrequest ready to commit by selecting  Stage file  from the options menu.

  10. Click the Commit button at the top to commit the file.

  11. In the message box, enter "Adding an item for my wish list."

  12. Click the Commit button under the box. From Sourcetree, you see that the file has been updated on the wish-list branch.

Step 2. Merge file changes from a branch

Your speakers were approved! Now it's time to update the main supply list with your wish-list item.

  1. First, you want to switch back to the main branch. From the left-side menu items in Sourcetree, hover your mouse over the right side of the Branches label so that the word Show appears.

  2. When Show appears, click it.
    Under the Branches heading, you will see the two branches for this repository, the main branch, and the wish-list branch.

  3. Double-click the main branch to switch to that branch.

  4. Click the Merge button.

  5. From the popup that appears, make sure the commit on your wish-list branch is highlighted. You are indicating that you want to add the commit from this branch to the main branch.

  6. If you have a Git repository, check this option at the bottom: Create a commit even if merge resolved via fast-forward.

  7. Click OK.
    You have updated the supplyrequest file in your main branch with your wish-list item.

  8. You are done.

Step 3. Push your change to Bitbucket

  1. From Sourcetree, click the Push button to push your committed changes.

  2. From the dialog box that appears, click the OK button to push changes to your local repository.

  3. Click the  Overview  page of your Bitbucket repository, and notice you can see your push in the Recent Activity stream.

  4. Click Commits and you can see the commit you made on your local system. Notice that the change keeps the same commit code that it had on your local system.

  5. Click  Source , then click the  supplyrequest  file.  You can see the last change to the file has the commit code you just pushed.

  6. Click the file history list to see the committed changes for this file, as shown in the following image.

You are done! 

That was intense! Maybe. Depends on how it compares to launching into space. Now that you know a lot more about Bitbucket, you are now prepared to run your space station's activities a lot better. Now, take a break and go do some star gazing.

Want to learn more about Bitbucket and Sourcetree? You can take on the challenge of updating a colleague's repository.

Still need help?

The Atlassian Community is here for you.