The distributed version control system Git is often used on hosting sites in order to simplify the updating of the site during development. Without this tool, you will have to download new versions manually, which takes more time. Having configured Git, you will be able to update everything automatically by pressing a single button. Later in the article, we will tell you how to connect Git to hosting and prepare it for work.
Open the control panel and go to the "Git Version Control" tab, it is located in the "Files" section. Here we need to create a repository by filling in all the fields below. It is important that the folder where the files will be stored is empty, otherwise the system will not allow you to use it as a repository.
Next, as soon as you need to update the site, go to the Git "Manage" section, select the repository you created earlier and initiate the update procedure. As a result of these actions, files located in a remote repository on the version control system website will be uploaded to your local server.
Here you can study information about all the recent periods of activity – this is useful during development and helps to identify the time point when certain problems with the site began.
To automate the update process, you need to create a file called .cpanel.yml in the root folder of the repository. Open it in edit mode and add the following lines:
- export DEPLOYATH=/home/your_user in_cpanel/path_to_repository
- /bin/cp -R folder_name_in_repository $DEPLOYATH
- /bin/cp file_name_in_the_repository $DEPLOYATH
In the line "export DEPLOYATH", be sure to specify the correct path to your repository, otherwise nothing will work. Next, if you need to specify several folders here at once, they should be registered separately, from a new line. After making all the changes, save the file, it is not necessary to restart the server.
After the work done above, you will be able to update the site files in a couple of clicks through the cPanel control panel, but this option is not as convenient for many as through the console. Therefore, we recommend using a secure connection via SSH protocol, and already through it to manage updates. Here are the commands you need:
That's basically all you need to know about setting up and connecting Git repositories on hosting. If you have any questions, please contact our specialists, we will be happy to help within our competence.