Git to Bluehost: Uploads web files to the Bluehost shared hosting server from local repository using Git
First of all you need to enable SSH service for your hosting. You can contact bluehost customer service for that. Now let’s go to the main point.
Suppose you’ve a website project on your PC named coderoffice and you use git to manage the project. Now you can take the advantage. You can easily update your website using git. Just follow these steps below.
Connect to the bluehost server using SSH from terminal:
ssh -p 2222 [email protected]
Create a repo. on the server and enter that dir:
mkdir ~/coderoffice.git
cd ~/coderoffice.git
Initialize it:
git init –bare
cd hooks
nano post-receive
Now paste these 2 lines and save the file:
#!/bin/bash
GIT_WORK_TREE=/home/username/public_html git checkout -f
Above script will transfer project files to public_html dir automatically whenever you push from the local repo. So change the permission of this file to be executed:
chmod +x post-receive
That’s it. That’s the simple git repo setup on the hosting account. Now let’s go to add the remote repository to your local repo which is coderoffice on your PC.
Open the terminal or gitbash (whatever you use) inside the coderoffice. To add bluehost remote repo:
git remote add bluehost ssh://[email protected]:2222/home/username/coderoffice.git
Now you can easily push:
git push bluehost master
Enjoy!!