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

# Using Git

> The popular Git revision control system is pre-installed on your server! Learn about it's advantages and how to use it.

This article is an introduction to using the Git version control system on hosting.com servers.

<Note>
  For information about how to configure a Git client to work with hosting.com servers, please see [this article](/docs/configuring-a-git-client).
</Note>

## About Git

The popular Git version control system is installed on all hosting.com shared and reseller accounts. For VPS and Dedicated Server accounts, you can install Git manually yourself, or we can install it for you upon request. Like other version control systems, Git enables you to track multiple revisions of files and directories.

The following sections are a brief introduction to Git's basic features.

<Note>
  Git has numerous features and commands, many of which are beyond the scope of this article. For detailed information about all of Git's commands, please see the\
  [official Git documentation](https://git-scm.com/doc).
</Note>

## Creating a repository

To create a Git repository, all you have to do is log in to your hosting.com account using SSH, and then type the following command:

```bash theme={null}
git init repository
```

Replace ***repository*** with the name of the directory where you want to create the repository (if the directory does not already exist, the **git init** command creates it).

Change the current working directory to the new repository:

```bash theme={null}
cd repository
```

To take a snapshot of all of the files currently in the repository directory, type the following command:

```bash theme={null}
git add .
```

The **git add** command puts the files in a temporary staging area that Git calls the "index". To commit the files to the repository permanently, type the following command:

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

A text editor opens, and you can type a commit message that describes the changes. Save the message, and then Git adds the changes to the repository.

<Note>
  You may receive the following message when you try to commit changes:

  ```text theme={null}
  Please tell me who you are.
  ```

  If you receive this message, type the following commands, using your own e-mail address and name:

  ```bash theme={null}
  git config --global user.email "you@example.com"
  git config --global user.name "Your Name"
  ```
</Note>

## Making changes to a repository

Git makes it easy to update a repository. After you edit a file or files, you update Git's file "snapshot" by using the **git add** command. To make the changes to the repository permanent, use the **git commit** command.

<Tip>
  You can combine the **git add** and **git commit** commands by typing the following command instead:

  ```bash theme={null}
  git commit -a
  ```

  You can even include the commit message on the command line by using the **-m** option. Replace ***message*** with your commit message:

  ```bash theme={null}
  git commit -a -m "message"
  ```
</Tip>

To view changes you have made to files in the repository since the last commit, type the following command:

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

Similarly, to view a list of changes that have already been committed to the repository, type the following command:

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

## Working with branches

A single Git repository can maintain multiple development branches. For example, you could create a "testing" branch and a "production" branch to track changes for different versions.

To create a new branch, type the following command, replacing ***name*** with the name of the new branch:

```bash theme={null}
git branch name
```

To see a list of all branches in a repository, type the following command:

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

The asterisk (**\***) next to a branch name indicates the current working branch. If you want to work on another branch, type the following command, replacing ***name*** with the name of the branch:

```bash theme={null}
git checkout name
```

You can then make changes in the branch and commit them with the **git commit** command. If you switch to another branch, you will not see those changes in the branch.

### Merging changes from another branch

To merge changes from one branch into another branch, type the following command. Replace ***name*** with the name of branch that has the changes you want to merge:

```bash theme={null}
git merge name
```

The changes in source branch ***name*** are then merged into the destination branch (the current working directory).

## Cloning a repository

You can "clone" repositories. When you clone a repository, git makes an exact copy of an existing repository. For example, say you have a repository named *project*. To clone the repository into a directory named *projectclone*, you would type the following command, replacing ***username*** with your own account username:

```bash theme={null}
git clone /home/username/project /home/username/projectclone
```

Now there is an exact copy of the *project* repository in the *projectclone* directory.

Suppose you (or another developer) make changes in the *projectclone* directory that you want to pull back into the original *project* directory. To do this, you would type the following commands, again replacing ***username*** with your own account username:

```bash theme={null}
cd /home/username/project
git pull /home/username/projectclone master
```

The **git pull** command fulfills two functions. First, it fetches changes from a remote repository (in this case, the *projectclone* repository). Second, it merges those changes into the current working repository (in this case, the *project* repository).

<Note>
  If you try to clone a Git repository stored on a remote server (such as GitHub) by using HTTPS, you may receive the following error message:

  ```text theme={null}
  error: error setting certificate verify locations:
    CAfile: /etc/pki/tls/certs/ca-bundle.crt
    CApath: none
  while accessing https://example.com/repository/

  fatal: HTTP request failed
  ```

  This error occurs when your account has the jailshell enabled. Please open a ticket on the Hosting Panel at [https://my.hosting.com](https://my.hosting.com) and request normal shell access for your account.
</Note>

## More information

To view the official Git documentation, including reference guides, tutorials, cheat sheets, and more, please visit [http://git-scm.com/documentation](http://git-scm.com/documentation).

## Related articles

* [Configuring a Git client](/docs/configuring-a-git-client)
* [Using a newer version of Git](/docs/using-a-newer-version-of-git)
* [Configuring Subversion](/docs/configuring-subversion)
* [Using Mercurial](/docs/using-mercurial)
* [Configuring CVS](/docs/configuring-cvs)
