Clone your repository and manage files locally

On this page

Still need help?

The Atlassian Community is here for you.

Ask the community

  1. Set up Sourcetree
  2. Create a personal repository for the tutorial
  3. Clone your repository and manage files locally
  4. Commit and push changes

In this step you will clone your personal repository to your local computer. Cloning your repository locally creates a file directory on your computer that will kept in synch with your online repository. 

About cloning...

Making changes to live source files makes your website vulnerable to user errors. Since we all make mistakes, we instead clone the source files locally and make our changes on our own computer where we can first test that our changes won't break things in the process. Once we verify things are as they should be we then can push our changes to the live source files (usually a master branch). From there, others can pull in our changes to their local copy, and update files of the website.

  1. Clone your personal repository using Sourcetree (or the command line)
    1. On the side navigation, click Clone, then Clone in Sourcetree to create a local directory where you can store the website files. 

      This opens the Clone New dialog in Sourcetree.
    2. Within Sourcetree, choose the appropriate destination for your personal repository, then click Clone.
      You'll arrive at the empty directory in Sourcetree, and an empty directory named website was created on your local computer.
  2. Download the source files and unzip them into the empty directory you just created.
  3. Add the files to your personal repository using Sourcetree (or the command line).
    1. Select the files you added in the previous step by checking the box named Unstaged files.
       
      The files then appear in the Staged files pane.
    2. Click Commit, add a message in the comment box, and check the box Push changes immediately to origin/master.
       
    3. Go to your personal repository and verify the files were added.

Next step

Do it from the command line

  1. Clone your personal repository from the command line. You can also copy the command directly from your empty repository. Look under Working with your repository.
    From a terminal window, run these commands

    cd ~
    git clone http://<username>@<Bitbucket Data Center URL>/scm/<project key>/website.git
    Click for an explanation of these commands...
    cd ~
    Change directory to your home directory 
    git clone
    Command that copies the contents of the repository
    <username>
    Is the username you use to log in to the instance
    <Bitbucket Data Center URL>
    The URL for your Bitbucket Data Center instance
    <project key>
    The project key where your personal repository is
    website.git
    The name of your personal repository

    This creates an empty Git repository named TISwebsite

  2. Add the files to your personal repository from the command line.
    From a terminal window

    cd existing-project
    git init
    git add --all
    git commit -m "Initial Commit"
    git remote add origin http://<Bitbucket Data Center URL>/scm/tis/website.git
    git push -u origin master
    Click for an explanation of these commands...
    cd existing-project
    Change to the directory where you unzipped the files 
    git init
    Initialize the Git repository
    git add --all
    Adds the files to the repository
    git commit -m "Initial Commit"
    Adds a comment to the commit
    git remote add origin <url>
    git push -u origin master
    Adds the remote repository and pushes your files to the master branch

    Next step

Last modified on Oct 4, 2023

Was this helpful?

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