# Using Git version control in cPanel to install and update a site

> Use cPanel's Git Version Control tool to deploy a website from a repository and pull in later updates.

Source: https://helpcenter.ruachost.com/cpanel/files/using-git-version-control-in-cpanel-to-install-and-update-a-site/

Git is a distributed version control system commonly used for managing project files and tracking changes. The **Git Version Control** tool in cPanel provides an easy graphical interface for working with Git repositories without needing to use command-line commands.

You can use this tool to install a website from a Git repository and later pull updates whenever new changes are made in the repo. The example below demonstrates installing a simple “Hello World!” site, but the same process applies to any project.

This guide also explains how to work with *private* repositories using SSH keys.

## Installing the Site

Suppose a developer has created a project and stored it in a GitHub repository. To install this site:

1. Log in to cPanel.
2. On the **Tools** page, locate the **Files** section and click **Git Version Control**.
3. Click **Create**.
4. Make sure **Clone a Repository** is enabled.
5. In **Clone URL**, enter the repository URL from GitHub.
6. In **Repository Path**, enter the directory where you want the site stored.

   - Typically, this is **public_html**, but you can choose a subdirectory if needed.
7. In **Repository Name**, enter a descriptive name.
8. Click **Create**.

After creation, the site files (e.g., `index.html`) and a `.git` directory will appear in the document root.

> Note: The `.git` folder is hidden from website visitors.

## Updating the Site

If the developer later adds or changes files in the repository (for example, adds an `about.html` page), you can update your site:

1. Log in to cPanel.
2. Go to **Git Version Control** under **Files**.
3. Locate the repository and click **Manage**.
4. Open the **Pull or Deploy** tab.
5. Click **Update from Remote**.

The new files will now appear in your website folder.

## Cloning a Private Repository

Cloning a private repository requires authentication. If you try to clone a private repo directly, you may see an error like:

```
fatal: could not read Username for 'https://github.com': No such device or address
```

To clone a private repository, use **SSH keys** and the **ssh://** clone URL.

## Step 1: Generate an SSH Key Pair on your ruachost.com account

```
ssh-keygen -t rsa
```

## Step 2: View the public key

```
cat ~/.ssh/id_rsa.pub
```

Copy the key shown.

## Step 3: Add the Public Key to Your Git Provider

- GitHub: <https://docs.github.com/en/github/authenticating-to-github/connecting-to-github-with-ssh/adding-a-new-ssh-key-to-your-github-account>
- GitLab: <https://docs.gitlab.com/ee/ssh>
- Bitbucket: <https://confluence.atlassian.com/bitbucketserver/enable-ssh-access-to-git-repositories-776640358.html>

## Step 4: Test the SSH Connection

- GitHub:

  ```
  ssh -vT git@github.com
  ```

  GitLab:

  ```
  ssh -vT git@gitlab.com
  ```
- Bitbucket:

  ```
  ssh -vT git@bitbucket.org
  ```

## Step 5: Clone the Private Repository in cPanel

1. Go to **Git Version Control** in cPanel.
2. Click **Create**.
3. Enable **Clone a Repository**.
4. Use the **ssh://** format in the Clone URL, such as:\
   `ssh://git@github.com/username/repository.git`
5. Set your repository path (e.g., `public_html`).
6. Enter a repository name.
7. Click **Create**.

You can update this repository later the same way as described in the **Updating the Site** section.
