Using Git to push changes to your live website
This tutorial provides instructions how to set up a Git remote repository on your hosting server so that you can easily deploy the latest version of your website files.
In this tutorial, the Control Panel and SSH username is example. Therefore, the default root directory for the domain is /home/example/www/www. The server hostname is sXXX.sureserver.com. You should replace these values with the actual values for your account.
Set up remote Git repository
1. Connect to the server for your account via SSH. You can follow the instructions in our online manual.
2. The repository should not be accessible via the web. Therefore, you should create it in the private directory on your account. Go to the private directory:
Create a directory for the repository and enter that directory:
Note: Instead of mywebsite.git, you can use any name you like, but it should end with .git.
Create a bare repository and initialize it:
git --bare init
A bare repository is a repository that is created without a working tree (e.g. the actual files of the project). Note: If you already have a repository for your website, and it was originally created on GitHub after October 2020, you should add the following to the end of the initialization command: "--initial-branch=main".
3. In order for the files to be pushed to the correct location, you need to create a post-receive hook:
Add the following to the file and save it:
Note: Replace /home/example/www/www with the location of your live website files. The directory must exist.
Give the file executable permissions:
chmod +x hooks/post-receive
On your local computer
1. If you do not already have a repository for your website on your computer, you can initiate a new repository and add all files in the current directory with the following commands:
You should also add your first commit:
git commit -m "My website is ready"
2. Now you can add a remote to the repository:
Note: The name of the remote is production. You should replace example with your Control Panel/SSH username, your_server.com with the hostname of your server and /home/example/private/mywebsite.git with the location of the git repository.
3. Finally, you can push the website from your local computer to the hosting server:
This command instructs Git to push the current master branch to the production remote. Note: If your original repository was created on GitHub after October 2020, you should replace master with main.