Use Sourcetree branches to merge an update
- Create a Git or Mercurial repository
- Copy your repository and add files
- Pull changes from your repository on Bitbucket
- 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 on a team. 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. Even though branches work differently between Git and Mercurial, you create them in a similar way from Sourcetree.
- From Sourcetree, click the Branch button.
- Depending on whether you have a Git or Mercurial repository, you see a different popup for creating a new branch. From the New Branch or Create a new branch field, enter
wish-listfor the name of your branch.
- Click Create Branch or OK.
- From Sourcetree, click the Show in Finder button. The directory on your system opens.
- From the directory folder, open the
supplyrequestfile with a text editor.
Making a change to the file by adding the following item to the list of supplies:
- Save the file.
- 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
supplyrequestfile and initially committed it.
- If you have a Git repository, make
- Click the Commit button at the top to commit the file.
- In the message box, enter "Adding an item for my wish list."
Click the Commit button under the box. From Sourcetree, you see that the file has been updated on the
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.
- 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.
- When Show appears, click it.
Under the Branches heading, you will see the two branches for this repository, the main branch, and the
wish-listbranch. The main branch for a Git repository is called
master. The main branch for a Mercurial repository is called
Double-click the main branch (in this case master for Git or default for Mercurial) to switch to that branch.
- Click the Merge button.
- From the popup that appears, make sure the commit on your
wish-listbranch is highlighted. You are indicating that you want to add the commit from this branch to the main branch.
- If you have a Git repository, check this option at the bottom: Create a commit even if merge resolved via fast-forward.
- Click OK.
You have updated the
supplyrequestfile in your main branch with your wish-list item. Sourcetree will look slightly different based on whether you have a Git or Mercurial repository.
- If you have a Git repository, you are done. If you have a Mercurial repository, you will notice that you need to commit your changes. Click the Commit button at the top. The commit message defaults to a description with "Merge." Keep this message and go ahead and click Commit.
Step 3. Push your change to Bitbucket
From Sourcetree, click the Push button to push your committed changes.
From the dialog box that appears, click the OK button to push changes to your local repository.
Click the Overview page of your Bitbucket repository, and notice you can see your push in the Recent Activity stream.
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.
Click Source , then click the
supplyrequestfile. You can see the last change to the file has the commit code you just pushed.
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 teammate's repository.