Sourcetree - A free Git & Mercurial client | Atlassian (2023)

Sourcetree - A free Git & Mercurial client | Atlassian (1)

Step 1: Create a Git repository

Step 2: Copy your repository and add files

Step 3: Pull changes from your repository

Step 4: UseSourcetree branches to merge an update

Step 1: Create a Git repository

As our new Bitbucket space station administrator, you need to be organized. When you make files for your space station, you’ll want to keep them in one place and shareable with teammates, no matter where they are in the universe. With Bitbucket, that means adding everything to a repository. Let’s create one!

Step 1: Create the repository

Initially, the repository you create in Bitbucket is going to be empty without any code in it. That's okay because you will start adding some files to it soon. This Bitbucket repository will be the central repository for your files, which means that others can access that repository if you give them permission.You will also copy a version of that repository to your local system—that way you can update it from onerepo, then transfer those changes to the other.

Sourcetree - A free Git & Mercurial client | Atlassian (2)

Do the following to create your repository:

  1. FromBitbucket,clickthe+icon in the global sidebar and selectRepository. Bitbucket displays theCreate a new repositorypage. Take some time to review the dialog's contents. With the exception of theRepository type, everything you enter on this page you can later change.
    Sourcetree - A free Git & Mercurial client | Atlassian (3)
  2. Enter BitbucketStationSupplies for theNamefield. Bitbucket uses thisNamein the URL of the repository. For example, if the user the_best has a repository called awesome_repo, the URL for that repository would be https://bitbucket.org/the_best/awesome_repo.

  3. Keep the rest of the options as is unless you want to change them:

    • Access level —Leave theThis is a private repositoryboxchecked.A private repository is only visible to you and those with access. If this box is unchecked, anyone can see your repository.

    • Include aREADME? —If you recently created your account, this defaults to a tutorial README.For the purposes of this tutorial, pick either of theYesoptions, that way you'll start out with a file.

  4. FromVersion controlsystem, you can choose eitherGitorMercurial. If you aren't sure which one to go with, keepGitas your option.

  5. ClickCreate repository.Bitbucket creates your repository and displays itsSourcepage.

(Video) SourceTree for Git and Mercurial installation and configuration tutorial

Step 2: Explore your new repository

Take some time to explore the repository you have just created.To view the shortcuts available, press the?key on your keyboard.

Click+from the global sidebar for common actions for a repository. Scan through the links in the navigation sidebar to see what's behind each one, including the repositorySettingswhere you'll update repository details and other settings. Click theCommitsin the sidebar. If you included a README, you'll see one commit on that page.

Yourrepository is private and you have not invited anyone to therepository, so the only person who can create or edit therepository's content right now is you, therepositoryowner.

Sourcetree - A free Git & Mercurial client | Atlassian (4)

Now that you have a place to add and share your space station files, you need a way to get to it from your local system. To set that up, you want to copy the Bitbucket repository to your system. Sourcetree refers to copying a repository as "cloning" it. When you clone a repository, you create a connection between the Bitbucket server and your local system.

Sourcetree - A free Git & Mercurial client | Atlassian (5)

Step 1: Clone your repository to your local system

Use Sourcetree to clone your repository to your local system without using the command line.

  1. As you use Bitbucket more, you will probably work in multiple repositories. For that reason, it's a good idea to create a directory to contain all those repositories. So start by creating a directory on your local system and call itrepos.
  2. From Bitbucket, go to yourBitbucketStationSuppliesrepository.

  3. ClicktheClonebutton in the top right corner. Bitbucket displays theClone this repositorydialog.Sourcetree - A free Git & Mercurial client | Atlassian (6)

  4. From theClone this repositorydialog, clickClone in Sourcetree.

  5. From theClone Newdialog box, update theDestination Pathto/repos/bitbucketstationsupplies. This destination path refers to the directory you just created with the folder for the repository. TheNamefield remains the same with the folder name of the repository.Sourcetree - A free Git & Mercurial client | Atlassian (7)

  6. Click theClonebutton.

Congratulations! You've cloned your repository to your local system.

Step 2: Create a file, add it locally, and push it to Bitbucket

With the repository on your local system, you can start making a list of all the supplies you need for your space station. To do so, let's create a file for your supplies.

As you work on this section, the images may look slightly different, depending on whether you are working with a Git or Mercurial repository.

  1. Double-click the bitbucketstationsupplies repository in Sourcetree and notice that there is nothing to commit from your local repository to the remote repository.
    Sourcetree - A free Git & Mercurial client | Atlassian (8)

  2. Use a text editor to add the following three lines:
    space ice
    cream nerf
    darts telescope light shield

  3. Save the file as supplies.txt to the bitbucketstationsupplies directory on your local system.The supplies.txt file now appears in Sourcetree since you created it in your local repository.
    Sourcetree - A free Git & Mercurial client | Atlassian (9)

  4. Now is thepoint where you prepare asnapshot of the changes before committing them to the official history. From the options menu of the supplies.txt file, selectStage file(for a Git repository) orAdd file(for a Mercurial repository).
    Sourcetree - A free Git & Mercurial client | Atlassian (10)
    Sourcetree - A free Git & Mercurial client | Atlassian (11)

  5. Click theCommitbutton at the top to commit the file.

    (Video) Git Tutorial 1 - SourceTree Setup and Overview - Connect SourceTree to Github

  6. In the message box, enter "Initial commit."
    Sourcetree - A free Git & Mercurial client | Atlassian (12)

  7. Click theCommitbutton under the box. Your new file is now committed to the project history.
    Sourcetree - A free Git & Mercurial client | Atlassian (13)
    Up until this point, everything you have done is on your local system and is invisible to your Bitbucket repository until you push those changes to your remote Bitbucket repository.

  8. From Sourcetree, click thePushbutton to push your committed changes.Pushing lets you move one or more commits to another repository, which serves as a convenient way to publish contributions.
    Sourcetree - A free Git & Mercurial client | Atlassian (14)

  9. From the dialog box that appears, your next step depends on whether you are using Git or Mercurial:

    • Git–Under thePush?column, select the mainbranch to indicate that you are pushing that branch to origin and clickOK.
      Sourcetree - A free Git & Mercurial client | Atlassian (15)

    • Mercurial–Everything is automatic, so all you have to do is clickOK.

  10. Go to yourBitbucketStationSuppliesrepository in Bitbucket.

    • If you clickCommitsin the sidebar, you'll see your commit in the repository.Bitbucket combines all the things you just did into that commit and shows it to you.

    • If you clickSourcein the sidebar, you'llsee your file in the repository, the supplies.txt file you just added.
      Sourcetree - A free Git & Mercurial client | Atlassian (16)

Step 3: Pull changes from your repository

Next on your list of space station administrator activities, you need to file out a request for new supplies.Let's set up a system for getting supplies to our Bitbucket space station. With just a bit more knowledge of Bitbucket and Sourcetree, we'll be supporting our space exploration for years to come!

Step 1: Create a file in Bitbucket

To add your supply request file, do the following:

  1. From yourBitbucketStationSuppliesin Bitbucket,clickSourceto open the source directory. Notice you only have one file,supplies.txt, in your directory.
    Sourcetree - A free Git & Mercurial client | Atlassian (17)

    • A.Source page:Click the link to open this page.

    • B.Branch selection:Pick the branch you want to view.

    • C. More options button:Click to open a menu with more options, such as 'Add file'.

    • D. Source file area: View the directory of files in Bitbucket.

  2. From theSourcepage, click theMore optionsbuttonin the top right cornerand selectAdd filefrom the menu.TheMore optionsbuttononly appears after you have added at least one file to the repository. A page for creating the new file opens, as shown in the following image.
    Sourcetree - A free Git & Mercurial client | Atlassian (18)

    • A. Branch with new file:Change if you want to add file to a different branch.

    • B. New file area:Add content for your new file here.

  3. Entersupplyrequestin thefilenamefield.

  4. SelectHTMLfrom theSyntax modelist.

  5. Add the following HTML code to the text area:

    We are requesting additional supplies. Please send us the following:

    (Video) Git and Mercurial Client For Mac and Window



    • space ice cream

    • nerf darts

    • telescope light shield

  6. ClickCommit. TheCommit messagefield appears with the message:supplyrequest created online with Bitbucket.

  7. ClickCommitunder the message field.

You now have a new file in Bitbucket!You are taken to a page with details of the commit,where you can see the change you just made:

Sourcetree - A free Git & Mercurial client | Atlassian (19)

If you want to see a list of the commits you've made so far,clickCommitsin the sidebar.

Step 2: Pull changes from a remote repository

Now we need to get that supply request form onto your local system. The process is pretty straight forward, basically just the reverse of the push you used to get the supplies.txt file into Bitbucket.

To pull the file into your local repository, do the following:

  1. Open your repository in Sourcetree, and click the Pull button.
    Sourcetree - A free Git & Mercurial client | Atlassian (20)
    A popup appears to indicate that you are merging the file from Bitbucket to your local repository.
    Sourcetree - A free Git & Mercurial client | Atlassian (21)

  2. ClickOKfrom this box. Sourcetree updates with a description of the merged file.
    Sourcetree - A free Git & Mercurial client | Atlassian (22)

  3. Navigate to your repository folder on your local system and you'll see the file you just added.

Fantastic!Now, you have finished the basic DVCS workflow (clone, add, commit, push, and pull) between Bitbucket and your local system.

Step 4: 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 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 documentationincludes 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.

  1. From Sourcetree, click theBranchbutton.
    Sourcetree - A free Git & Mercurial client | Atlassian (23)
  2. Depending on whether you have a Git or Mercurial repository, you see a different popup for creating a new branch. From theNew BranchorCreate a new branchfield, enter wish-list for the name of your branch.
    Sourcetree - A free Git & Mercurial client | Atlassian (24)
    Sourcetree - A free Git & Mercurial client | Atlassian (25)
  3. ClickCreate BranchorOK.

  4. From Sourcetree, click theShow in Finderbutton. The directory on your system opens.Sourcetree - A free Git & Mercurial client | Atlassian (26)

  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:

  7. anti-gravity speakers
  8. Save the file.

    (Video) SourceTree - How to Update Mercurial | The Call Stack

  9. Open the view in Sourcetree and notice that your repository now has uncommitted changes.
    Sourcetree - A free Git & Mercurial client | Atlassian (27)
    From here, everything you do is the same as you did when you added the supplyrequest file and initially committed it.

  10. If you have a Git repository,make supplyrequest.txt ready to commit by selectingStage filefrom the options menu.
    Sourcetree - A free Git & Mercurial client | Atlassian (28)

  11. Click theCommitbutton at the top to commit the file.

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

  13. Click theCommitbutton under the box. From Sourcetree, you see that the file has been updated on the wish-list branch.
    Sourcetree - A free Git & Mercurial client | Atlassian (29)

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 theBrancheslabel so that the wordShowappears.
    Sourcetree - A free Git & Mercurial client | Atlassian (30)
  2. WhenShowappears, click it. Under the Branches heading, you will see the two branches for this repository, the main branch, and the wish-list branch. The main branch for a Git repository is called main. The main branch for a Mercurial repository is called default.
    Sourcetree - A free Git & Mercurial client | Atlassian (31)
  3. Double-click the feature branch (in this case wish-list) to switch to that branch.

  4. Click theMergebutton.
    Sourcetree - A free Git & Mercurial client | Atlassian (32)

  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.
    Sourcetree - A free Git & Mercurial client | Atlassian (33)

  6. If you have a Git repository, check this option at the bottom:Create a commit even if merge resolved via fast-forward.
    Sourcetree - A free Git & Mercurial client | Atlassian (34)

  7. ClickOK.You have updated thesupplyrequestfile in your main branch with your wish-list item. Sourcetree will look slightly different based on whether you have a Git or Mercurial repository.
    Sourcetree - A free Git & Mercurial client | Atlassian (35)

  8. 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 theCommitbutton at the top. The commit message defaults to a description with "Merge." Keep this message and go ahead and clickCommit.

Step 3: Push your change to Bitbucket

  1. From Sourcetree, click thePushbutton to push your committed changes.

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

  3. Click theOverviewpage of your Bitbucket repository, and notice you can see your push in theRecent Activitystream.

  4. ClickCommitsand 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.
    Sourcetree - A free Git & Mercurial client | Atlassian (36)

  5. ClickSource, 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.Sourcetree - A free Git & Mercurial client | Atlassian (37)

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.

(Video) How to Use Sourcetree for Git Version Control System

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

Videos

1. SourceTree and Mercurial Version Control
(Ryan Miller)
2. Getting started with Git using SourceTree - Part 1: Version control
(Virtual Play)
3. Intro to Git with SourceTree
(Alex Lewis)
4. Install sourcetree and connect github repsitories
(Jinxter Games)
5. git flow with sourcetree in 5 minutes
(Gaur Associates)
6. How to connect sourcetree to our Github account? | Episode 10 | Part 2
(V Develop)
Top Articles
Latest Posts
Article information

Author: Edmund Hettinger DC

Last Updated: 02/25/2023

Views: 5666

Rating: 4.8 / 5 (78 voted)

Reviews: 93% of readers found this page helpful

Author information

Name: Edmund Hettinger DC

Birthday: 1994-08-17

Address: 2033 Gerhold Pine, Port Jocelyn, VA 12101-5654

Phone: +8524399971620

Job: Central Manufacturing Supervisor

Hobby: Jogging, Metalworking, Tai chi, Shopping, Puzzles, Rock climbing, Crocheting

Introduction: My name is Edmund Hettinger DC, I am a adventurous, colorful, gifted, determined, precious, open, colorful person who loves writing and wants to share my knowledge and understanding with you.