> ## Documentation Index
> Fetch the complete documentation index at: https://citodocs.prostack.host/llms.txt
> Use this file to discover all available pages before exploring further.

# Working with Git

> Deploy code using Git from GitHub, Bitbucket, or other platforms

You can connect sites to Git repositories, allowing you to deploy changes to your sites automatically. In Cito we map repositories 1:1 with sites in the dashboard.

You can connect a repository to your site at the Create Site wizard, or, for existing sites, from the Site Settings page.

<img src="https://mintcdn.com/prostackhosting/mdYxEEoAStQaBUbz/images/screenshots/gitconnect.png?fit=max&auto=format&n=mdYxEEoAStQaBUbz&q=85&s=51f8bed582642ca87fb938fe79d39dc6" alt="Git Connect" width="2076" height="274" data-path="images/screenshots/gitconnect.png" />

You'll be prompted to authorise Cito to connect to your github account or organisation. From there, you can select the repository to connect, as well as the branch. By default, we clone repositories to the **Document root** of your site. This applies even if you use a custom docroot.

Once connected you'll be able to view recent commits and click 'Deploy latest' to pull your changes automatically.

<img src="https://mintcdn.com/prostackhosting/mdYxEEoAStQaBUbz/images/screenshots/gitconnected.png?fit=max&auto=format&n=mdYxEEoAStQaBUbz&q=85&s=018793d893e0c6e1367ebb9683e9ffba" alt="Git Connected" width="2080" height="620" data-path="images/screenshots/gitconnected.png" />

## CLI usage

Git is pre-installed by default to allow you to interact with repositories at Github, Bitbucket or other platforms. To do this you'll need to log in via SSH.

If you are using a CI system to deploy files to your website, you should ensure the credentials you use are that of the site, **not** the `admin` user.
This ensures permissions are correct.

<Warning>
  Note that cloning a repository via SSH will mean it doesn't show up in the site settings page. We recommend connecting your repositories via the Cito dashboard first.
</Warning>

## Document roots

The default document root on Cito servers is `public_html` inside your home directory. This can be changed via Site Settings if you need to.

## SSH keys

You may need to add additional SSH keys to a site in order to allow external systems to connect.

To do this, see [SSH](/deploying/ssh).

### Generating a new SSH keypair

If you wish to generate a new SSH key pair, you can do so by running the following SSH command. This is useful if you are working with private repositories and need to authenticate with Github or Bitbucket to clone them to your server.

Be sure to do this as the site user you're working with; if you generate a keypair as `admin` you'll need to then copy the keys to the relevant user.

```bash theme={null}
ssh-keygen -t ed25519
```

You'll be prompted for a key passphrase & location. It is safe to accept the defaults.

Once you've done this, you can add the public key to your Github account.

## Cloning a repository

To clone a git repository, navigate to your chosen repository and run:

```bash theme={null}
git clone https://<repo url> .
```

## Pulling the latest version of a repository

To pull your latest changes, run:

```bash theme={null}
git pull
```

## Additional resources

There are a number of resources available online to help you learn Git. Here are some of our favourites:

* [Git- the simple guide](https://rogerdudler.github.io/git-guide/)
* [Git cheat sheet](https://training.github.com/downloads/github-git-cheat-sheet/)
* [Learn Git- Atlassian](https://www.atlassian.com/git)
