Clone and make a change on a new branch

On this page

Still need help?

The Atlassian Community is here for you.

Ask the community

  1. Create a repository and add a teammate
  2. Clone and make a change on a new branch
  3. Create a pull request to merge your change

In a typical team context, you'd most likely already have the repository cloned before creating a branch. So that's what we're going to do first before you set up your own branch.

I'm using Git!

Step 1. Clone your repository to your local system

Let's get it onto your local system so that you can really start working on it.

  1. From the repository, click the Clone button in the top right.
    Bitbucket displays the Clone this repository dialog. By default, the clone dialog sets the protocol to HTTPS or SSH, depending on your settings. As a result, you don't need to  change your default protocol.
  2. Copy the clone command.
  3. From a terminal window, change into the local directory where you want to clone your repository.
    cd ~/<path_to_directory>
  4. Paste the command you copied from Bitbucket, for example:
    git clone https://breezy@bitbucket.org/powerstars/first-impressions.git

    Cloning into 'first-impressions'...
    Password for 'https://breezycloud@bitbucket.org': 
    remote: Counting objects: 6, done.
    remote: Compressing objects: 100% (5/5), done.
    remote: Total 6 (delta 1), reused 0 (delta 0)
    Unpacking objects: 100% (6/6), done.

For more details, check out our cloning video to see how it's done:

Step 2. Create a branch and pull in locally

Now that your repository is all set up, next comes the fun part. You can create branches locally or through Bitbucket. Let's create one from Bitbucket for the purposes of this tutorial.

  1. Click Branches from the left navigation. You'll see that you already have one branch — your main branch, master.
  2. Click Create a branch in the top right corner.
  3. After you create a branch, you need to check it out on your local system. Bitbucket provides you with a fetch and checkout command that you can copy and paste into your command line, similar to the following:
    git fetch && git checkout my-updates

    Password for 'https://breezycloud@bitbucket.org': 
    From https://bitbucket.org/planetbreezycloud/first-impressions
     * [new branch]      my-updates -> origin/my-updates
    Branch 'my-updates' set up to track remote branch 'my-updates' from 'origin'.
    Switched to a new branch 'my-updates'

As you can see, you've switched to your new branch locally, allowing you to work on and push that separate line of code.

Step 3. Make a change to the branch

Now, it's your turn to makes some changes to your repository. Like the file mentions, you can go as crazy or as simple as you like. Change up the CSS. Add more files. Compose a space opera. Or simply answer the questions.

  1. Open the survey.html file (or whatever you named it) with a text editor.
  2. Make your changes, big or small, and then save and close the file.

  3. From your terminal window, you should still be in the repository directory unless you've changed something. Display the status of the repository with git status. You should see the survey.html file you modified. If you added or modified other files, you'll see those as well.

    git status
    On branch my-updates
    Your branch is up-to-date with 'origin/my-updates'.
    Changes not staged for commit:
      (use "git add <file>..." to update what will be committed)
      (use "git checkout -- <file>..." to discard changes in working directory)
            modified:   survey.html
    no changes added to commit (use "git add" and/or "git commit -a")

  4. Add your changes locally with git add <filename>:
    git add survey.html

  5. Commit your changes locally with  git commit -m "your commit message":
    git commit -m "Answered questions"
    [my-updates 7506040] Answered questions
     1 file changed, 3 insertions(+), 3 deletions(-)

  6. Enter git push origin <branch_name> to push the changes to your branch on Bitbucket, and enter your password to finish pushing changes.
    git push origin my-updates

    Password for 'https://breezycloud@bitbucket.org': 

    Counting objects: 3, done.

    Delta compression using up to 8 threads.

    Compressing objects: 100% (3/3), done.

    Writing objects: 100% (3/3), 350 bytes | 350.00 KiB/s, done.

    Total 3 (delta 1), reused 0 (delta 0)

    To https://bitbucket.org/planetbreezycloud/first-impressions.git

       454ccaf..7506040  my-updates -> my-updates

    Branch master set up to track remote branch master from origin.

  7. From Bitbucket, click the Source page of your repository. You should see both branches in the dropdown. Any other commits you make to my-updates will also appear on that branch.

I'm using Sourcetree!

Step 1. Clone your repository to your local system

Let's get it onto your local system so that you can really start working on it.

  1. From the repository, click + in the global sidebar and select Clone this repository under Get to work.
  2. Click the Clone in Sourcetree button.
  3. From the Clone New window, update the Destination Path to <path_to_repo_directory>/first-impressions/.

  4. Click the Clone button.

To see how it's done, check out the Clone a repository part of our video here:

youtu.be

Step 2. Create a branch and pull in locally

Now that your repository is all set up, next comes the fun part. Because branches aren't only a Bitbucket concept, you can create one locally. However, we're going to create one from Bitbucket for the purposes of this tutorial.

  1. Click Branches from the left navigation. You'll see that you already have one branch — your main branch.
  2. Click Create a branch in the top right corner.
  3. Enter a Branch name and click Create. If you aren't sure what to name your branch, go with something like my-updates.
  4. After you create a branch, you need to check it out from your local system. To do so, click the Check out in Sourcetree button.

  5. From the Checkout Existing dialog in Sourcetree, click Checkout.

Now you've got a branch in Bitbucket and it's checked out to your local system, allowing you to work on and push that separate line of code.

Step 3. Make a change to the branch

Now, it's your turn to makes some changes to your repository. Like the file mentions, you can go as crazy or as simple as you like. Change up the CSS. Add more files. Compose a space opera. Or simply answer the questions.

  1. From the repository in Sourcetree, click the Show in Finder button.
  2. Open the survey.html file (or whatever you named it) with a text editor.
  3. Make your changes, big or small, and then save and close the file.

  4. Open Sourcetree and notice that your repository has Uncommitted changes.
  5. (Git only) Add the file to the staging area:
    1. Select the Uncommitted changes line.
    2. From the Unstaged files list, place a checkmark next to the survey.html file (and any other files with uncommitted changes).
    3. From the Confirm Stage? dialog, click OK.
  6. Click the Commit button at the top to commit the file.
  7. Enter a commit message in the space provided, something like Answered questions.
  8. Click the Commit button under the message box. When you switch back to the view, you see that the file has been committed but not pushed to the Bitbucket repository.
  9. From Sourcetree, click the Push button to push your committed changes.
  10. From the dialog that appears, click OK to push your branch with the commit to Bitbucket.

  11. From Bitbucket, click the Source page of your repository. You should see both branches in the dropdown. Any other commits you make to my-updates will also appear on that branch.

I'm using Mercurial!

Step 1. Clone your repository to your local system

Let's get it onto your local system so that you can really start working on it.

  1. From the repository, click the Clone button in the top right.
    Bitbucket displays the Clone this repository dialog. By default, the clone dialog sets the protocol to HTTPS or SSH, depending on your settings. As a result, you don't need to  change your default protocol.
  2. Copy the clone command.
  3. From a terminal window, change into the local directory where you want to clone your repository.
    cd ~/<path_to_directory>
  4. Paste the command you copied from Bitbucket, for example:
    hg clone https://breezy@bitbucket.org/powerstars/first-impressions.git

    realm: Bitbucket.org HTTP
    user: breezycloud
    password:
    destination directory: myteamquotes
    requesting all changes
    adding changesets
    adding manifests
    adding file changes
    added 2 changesets with 2 changes to 2 files
    new changesets 6b1b040ef1e9:74e1b6efc189updating to branch default
    2 files updated, 0 files merged, 0 files removed, 0 files unresolved

For more details, check out our cloning video to see how it's done:

Step 2. Create a branch and make your changes

Now that your repository is all set up, next comes the fun part. If you want to create a Mercurial branch, the best way to do it is locally.

  1. From a terminal window, change into the repository directory where you want to clone your repository.
    cd ~/<path_to_directory>
  2. From your local repository, create a branch with hg branch and the name you want to give the branch. If you aren't sure what to name your branch, go with something like my-updates.
    hg branch my-updates

    Nothing changes in the working directory yet. The branch command tells Mercurial the branch name to use with your next commit. If you enter the hg branches command to see all your branches, you'll see you still only have the default branch.

  3. Open the survey.html file (or whatever you named it) with a text editor.
  4. Make your changes, big or small, and then save and close the file.

  5. Display the status of the repository with git status. You should the survey.html file you modified. If you added or modified other files, you'll see those as well.

    hg status
    M survey.html

  6. Commit your changes locally with  hg commit "commit message":
    hg commit -m "Answered questions"

  7. Run the hg branches command now to see your new branch:
    hg branches 

    my-updates                  3159:6ab9a159fc43
    default                     3158:5b8b05432593 (inactive)
  8. Push the feature branch back to Bitbucket. To do so, you'll need to do a force push with hg push -f.
    hg push -f

    pushing to https://breezycloud@bitbucket.org/planetbreezycloud/second-impressions
    http authorization required for https://bitbucket.org/planetbreezycloud/second-impressions
    realm: Bitbucket.org HTTP
    user: breezycloud
    password: 
    searching for changes
    remote: adding changesets
    remote: adding manifests
    remote: adding file changes
    remote: added 1 changesets with 1 changes to 1 files
  9. From Bitbucket, click the Source page of your repository. You should see both branches in the dropdown. Any other commits you make to my-updates will also appear on that branch.

Next

Last modified on Jul 2, 2018

Was this helpful?

Yes
No
Provide feedback about this article
Powered by Confluence and Scroll Viewport.