Manage website using Git – Shared, VPS, Dedicated

In this article, you will learn how you can manage your website, hosted on Shared, VPS, or dedicated server, using Git version control.

Video tutorial:

This tutorial works for all Shared, VPS, and dedicated hosting servers.

I have created a simple “Hello world” PHP file.

<?php

echo "Hello world";

I have created a sub-domain and Git repo on my shared hosting. You can check it from the video above.

Once a Git repo is created, it will give you an SSH path. I am going to open CMD in my folder and initialize Git in it.

cd "my-project-folder"
git init
git remote add origin ssh://adnantech@adnan-tech.com/home2/adnantech/git.adnan-tech.com
git status
git add .
git commit -m "Initial commit."
git push origin master

It will ask for your username and password. You can enter the credentials you use to log in to your hosting server.

If you receive the following error:

fatal: bad config value for ‘receive.denycurrentbranch’ in config

You can fix it by first accessing SSH from your terminal: (make sure to replace it with your username and IP address)

ssh -p 2222 adnantech@162.241.216.155

It will again ask for your password. Once the password is entered, you will be entered into the SSH terminal.

Once inside the SSH terminal, enter the following command:

which git-receive-pack

It will return the path of your Git receive pack. Copy it. Then push the code using the following command:

git push origin master -u --exec=your_git_receive_pack

Replace “your_git_receive_pack” with your Git receive-pack returned from the previous command.

I am going to make some changes in my code.

<?php

echo "Hello world of programming...";

Then I am going to push again.

git add -A
git commit -m "Changes made."
git push origin master -u --exec=your_git_receive_pack

You will now see updated code pushed to your website.

So that’s it. That’s how you can manage your shared, VPS, or dedicated server’s website code using Git.

You can watch the video if you are having problems following the article.

If you still face any issues with this, you can let me know.

More: Learn how to deploy Node JS app on VPS or dedicated hosting.