Home
/
SiteGround Git Tool Tutorial
/
How to Clone a GIT Repository

How to Clone a GIT Repository

This tutorial explains how to clone your Git repository to your local machine. This way you can work and develop your project locally.

Get an SSH key for your site

The Git system uses the SSH protocol to transfer data between the server and your local computers. This means that in order to clone the repository you need to have SSH access to your website. To get an SSH key for your site, go to your Site Tools > Devs > SSH Keys Manager. If you still do not have a key, you can create one there. Once you have a key, go to the Action menu > Private Key:

 

A new window will appear in which you will be provided with your SSH key:

Due to security reasons, the password for your SSH key will not be displayed in the tool. If you do not know your SSH key password, you will have to generate a new key from Devs > SSH Keys Manager in Site Tools. You can check our detailed SSH tutorial for more information on how to manage your SSH keys.

Commands to clone locally and commit back online

Linux/Mac

In this example, the command will clone the repository for the main WordPress site. It is available in your Site Tools > Devs > Git > go to the Action menu for the corresponding repository > Git Info:

git clone ssh://username@server_name:18765/home/customer/www/yourdomain.com/public_html/

Your computer will need several minutes to clone the repository. After that, you should see your application copied on your local computer. If you want to clone your site to a specific folder you can use the following modified command:

git clone ssh://username@server_name:18765/home/customer/www/yourdomain.com/public_html/ /home/user/Desktop/mainsitegit

The above command will clone the repository and the application will be saved on your local computer in the “/home/user/Desktop/mainsitegit” folder. At this stage, the site will be downloaded to your local computer and you can edit your files via your favorite editor. To commit the changes to your local GIT repository you can use the following command:

git commit -a -m "Commit comment."

The above command will commit the changes to your local repository and the comment will be added to the Git logs. To push the changes to the server you have to use the following command:

git push

The system will connect to the server and upload the files that have been modified on your local computer.

Windows

Start by downloading Git for Windows and installing it using the default settings. Run the Git Bash application once the installation is complete and go to the C:/Users/YourUser directory using the following command:

cd /C/Users/YourUsername

Replace YourUsername in the above command with your Windows Account username. Then create a new folder named “.ssh” and navigate to it using:

mkdir .ssh; cd .ssh

Here, create an empty file, paste your SSH private key inside it and save the file. Our SSH Tutorial can help you do that. Once the key file is created change its permissions to 600 with:

chmod 600 file_name

where file_name is the name of the file.

After that run the following command:

eval `ssh-agent -s`

to start the SSH agent and add the private key to it using:

ssh-add ~/.ssh/file_name

where file_name is the key file name.

Now all that is left is to navigate to the folder where you want to clone your repository and run the clone command. It is available in your Site Tools > Devs > Git > go to the Action menu for the corresponding repository > Git Info:

git clone ssh://username@server_name:18765/home/customer/www/yourdomain.com/public_html/

It will take several minutes to clone the repository. After that, you should see the repository copied on your local computer. At this stage, the site will be downloaded to your local computer and you can edit your files via your favorite editor. To commit the changes to your local GIT repository you can use the following command:

git commit -a -m "Commit comment."

The above command will commit the changes to your local repository and the comment will be added to the Git logs. To push the changes to the server you have to use the following command:

git push

The system will connect to the server and upload the files that have been modified on your local computer.

Share This Article