DEV Community

Cover image for Pushing Code to cPanel with Git
Muhammad Furqan
Muhammad Furqan

Posted on

Pushing Code to cPanel with Git

In the fast-paced realm of web development, effectively and efficiently deploying code is a common hurdle. Traditional methods of deployment, particularly with vanilla HTML, CSS, and JS, often involve manual processes, FTP transfers, and the potential for human errors. This can consume time, be prone to mistakes, and disrupt a smooth development workflow.

The traditional process of pushing code to cPanel using Git can be laborious. One challenge frequently encountered is integrating cPanel with online Git repositories like GitHub or GitLab. This requires additional SSH logins, managing credentials, and manually pulling changes. These obstacles often impede the seamless progress of projects.

In this article, we will explore a simple method to overcome these challenges and improve your development experience. I will guide you through the process of pushing your code directly to cPanel using Git, streamlining your workflow and optimizing your development journey.

Prerequisites

To proceed, make sure you have SSH access to your cPanel account.

You should also have Git installed on your local machine.

Step 1: Creating a Repository on cPanel

The first step is to create a Git repository on your cPanel account.

Log in to your cPanel account via SSH.

Create and navigate to the directory where you want to push your code. For example, let's say you want to push code to the app directory.

mkdir ~/app
cd ~/app
Enter fullscreen mode Exit fullscreen mode

Initialize a new git repository using the following command.

git init --initial-branch=main
Enter fullscreen mode Exit fullscreen mode

By default, pushing a branch to a non-bare Git repository in which the branch is currently checked out is not allowed. However, you can enable such a push by setting the receive.denyCurrentBranch option. For more detail click here.

git config receive.denyCurrentBranch updateInstead
Enter fullscreen mode Exit fullscreen mode

Step 2: Including cPanel Repository as a Remote

Next, you should include the cPanel Git repository as a remote in your local Git repository.

git remote add cpanel ssh://username@domain_name_or_ip:port/~/app
Enter fullscreen mode Exit fullscreen mode

Make sure to replace username, domain_name_or_ip, and port with your own SSH credentials.

Step 3: Pushing Code to cPanel

Now, you are ready to push your code to the cPanel repository.

git push cpanel main
Enter fullscreen mode Exit fullscreen mode

This command will push the main branch of your local repository to the main branch of the cPanel repository. If you wish to push your local master branch instead, you can use the following command.

git push cpanel master:main
Enter fullscreen mode Exit fullscreen mode

Conclusion

Utilizing Git for code deployment can greatly improve your workflow, making the process more efficient and manageable. By following these instructions, you can effortlessly push your code to cPanel and ensure a seamless deployment process for your web projects. Happy deployment!


Stay updated with the latest tech insights by following me!

Are you in need of a highly skilled freelancer specializing in full-stack development to tackle your development challenges? Get in touch with me on Upwork.

Curious about my current projects? Take a look at my Personal Website and GitHub.

Interested in connecting? Feel free to reach out to me on LinkedIn. You can also find me on Twitter

Top comments (0)