How to Host Git Repositories with cPanel

You are here:
Estimated reading time: 2 min

Hosting Git repositories on cPanel is a great way to manage code versions and collaborate with others. cPanel offers built-in support for Git, which makes it easier to host and manage your repositories directly from the control panel. Below is a step-by-step guide on how to host Git repositories with cPanel:

Prerequisites

  1. A cPanel account with Git version control enabled.
  2. Access to your cPanel dashboard.
  3. SSH access (optional but recommended for advanced operations).

Step 1: Access Git Version Control in cPanel

  1. Log in to your cPanel account.
  2. Scroll down to the Files section and click on Git Version Control.

Step 2: Create a New Repository

  1. Click the Create button in the top-right corner.
  2. Choose the repository type:
    • Clone a Repository: This is for cloning an existing remote repository (e.g., from GitHub or GitLab).
    • Create a New Repository: If you want to create a brand new repository.
  3. Repository Path:
    • Specify the directory path where the repository will be stored. For example: ~/repositories/my-project.
    • cPanel will automatically create the directory if it doesn’t exist.
  4. Repository Name:
    • Choose a meaningful name for your repository, like my-project-repo.
  5. Repository URL (if cloning):
    • Provide the URL of the remote repository you want to clone. For example: https://github.com/username/repo.git.
  6. Click Create or Clone to complete the setup.

Step 3: Manage the Repository

  1. Once the repository is created, it will be listed under the Git Version Control interface in cPanel.
  2. You can:
    • View repository details.
    • See the current branch.
    • Get the remote URL.
    • Use the “Pull or Deploy” button to pull changes from a remote repository.
    • Click the Manage button to view more options like changing the branch or viewing the logs.

Step 4: Accessing the Repository via SSH or HTTP

  1. SSH Access:
    • If SSH access is enabled for your cPanel account, you can access the repository using SSH.
    • Use the following command to clone your repository locally (replace example.com with your domain and my-project-repo with your repository name):
      git clone ssh://user@example.com/home/user/repositories/my-project-repo.git
      
  2. HTTP Access:
    • If you want to provide HTTP access, make sure to set up an .htaccess file and configure webhooks if needed.

Step 5: Pushing Code to the Repository

  1. To push code to the repository, you can use a Git client like Git Bash or command-line Git.
  2. Use the following commands to push changes to your cPanel-hosted repository:
    git remote add origin ssh://user@example.com/home/user/repositories/my-project-repo.git
    git add .
    git commit -m "Initial commit"
    git push -u origin master
    

    Make sure to replace user and example.com with your cPanel username and domain name, respectively.

Step 6: Setting Up Deployment (Optional)

  1. If you want to deploy your repository files to a live directory (e.g., your public_html), you can set up deployment options.
  2. Go to Git Version Control > Manage for the repository.
  3. Scroll down to the Deployment section.
  4. Click on Create or Update Deployment Script and set the script to deploy files to a specific directory.
    • Example deployment script:
      #!/bin/bash
      # This script deploys the files to public_html
      rsync -av --exclude='.git/' /home/user/repositories/my-project-repo/ /home/user/public_html/
      
  5. Save the script and run it to deploy the files whenever needed.

Additional Tips:

  • Branch Management: You can create, switch, and delete branches directly from the command line or via the cPanel interface.
  • Webhooks: For automated deployments, you can set up webhooks from your remote Git repository (like GitHub) to your cPanel server.

Common Issues and Troubleshooting

  • SSH Authentication Errors: Ensure your SSH keys are properly configured in cPanel and the .ssh/authorized_keys file is set up correctly.
  • Permission Issues: If you encounter permission issues, check the file and folder permissions for your repository and ensure the cPanel user has the necessary access.

After following these steps, you should be able to successfully host and manage Git repositories with cPanel. Let me know if you need help with any specific configuration or issue!

Was this article helpful?
Dislike 0

Author

Joshua

Web Hosting Geek Technical Support Staff G Online Sites