Have you ever made a change to your website and then accidentally overwritten everything? Shudder. This is where version control comes in! Imagine a magic tool that tracks all the changes made to your website files, allowing you to rewind to any previous version if needed. That's exactly what Git, a powerful version control system, does. The good news? cPanel offers a built-in Git interface to simplify this process.

Git empowers seamless collaboration and version tracking for your website's codebase. Whether you're a beginner, intermediate, or advanced user, this guide equips you with the knowledge to manage Git repositories using the cPanel interface, command line (CLI), and WebHostingM UAPI (for advanced users).

Why Version Control Matters

Before diving into the technical details, let's understand why integrating Git with WebHostingM's cPanel is beneficial for website owners.

Imagine a website development project where multiple people contribute code.

Version control ensures everyone works on the latest version and allows you to revert to previous versions if necessary. Git, a popular version control system, excels at this.

  • Version Control: Keep track of changes to your codebase over time, making it easy to revert to previous versions if needed.

  • Collaboration: Facilitate seamless collaboration with team members by managing code changes, merging branches, and resolving conflicts efficiently.

  • Deployment: Streamline the deployment process by automating tasks such as pushing changes to production environments directly from your repository.

 

Now, let's delve into the specifics of using Git within your WebHostingM cPanel account, catering to beginners, intermediate, and advanced users alike.

Choosing the Right Tool for the Job

WebHostingM cPanel offers three methods for managing Git repositories:

  1. cPanel GUI: A user-friendly interface suitable for basic tasks like creating, deleting, and browsing repositories.
  2. Command Line (CLI): The Terminal within cPanel provides more control for advanced users familiar with Git commands.
  3. WebHostingM UAPI (Advanced): This programmatic interface allows developers to automate Git tasks using scripts. (Note: Due to its complexity, UAPI is recommended for advanced users only.)

Important Note: Before making any significant changes to your website's files, creating a backup is crucial. WebHostingM offers backup options within your cPanel account.

 

Using the cPanel GUI: Simple Git Management

  1. Log in to your cPanel account.
  2. Navigate to "Files" and then "Git Version Control."
  3. The interface displays existing repositories.

Creating a New Repository:

  • Click "Create" in the top right corner.
  • Choose "Create a new repository" or "Clone an existing repository" depending on your needs.
  • Provide a name and path for the repository.
  • Click "Create."

Managing Existing Repositories:

  • Click on a repository name.
  • You can view details, pull/deploy changes (using cPanel's deployment tool), or remove the repository from cPanel's management.

 

Utilizing the Command Line (CLI) for Advanced Control

Prerequisites:

  • Shell access is enabled in your cPanel account. Make sure that your cPanel account includes shell access. Without shell access, you can only create, clone, delete, and view repositories. If you are using your local machine SSH, make sure that you have created an SSH public_key and have added it to your cPanel server. You either use your local machine Terminal to access your command line or cPanel's Terminal interface (cPanel >> Home >> Advanced >> Terminal) from within the WebHostingM cPanel interface.
  • Basic understanding of Git commands.

 

Common Git Commands:

Command Description
git clone $URL

 

Clones a remote repository to your local machine.

git init

 

Initializes a new Git repository in a directory.

git add $FILE

 

Adds a file to the staging area for the next commit.

git commit -m "$MESSAGE"

 

Creates a commit with a descriptive message.

git push origin <branch>

 

Pushes your local commits to the remote repository's specified branch.

 

Remember: The command line offers more control but requires a steeper learning curve.

 

WebHostingM UAPI (Advanced Users Only)

The UAPI allows programmatic management of cPanel features, including Git. Refer to the WebHostingM UAPI documentation for detailed instructions.

Below are the complete cPanel API command examples for managing Git repositories within your WebHostingM cPanel account:

Viewing Git Repositories (retrieve information about Git repositories in the cPanel account):

uapi --output=jsonpretty VersionControl retrieve

This feature does not allow the following characters in repository paths:

\ * | " ' < > & @ ` $ { } [ ] ( ) ; ? : = % #

This function does not allow repositories that exist in the following cPanel-controlled directories:

.cpanel .htpasswds .ssh .trash access-logs cgi-bin etc logs perl5 mail spamassassin ssl tmp var

You can create repositories in some of these directories on the command line. They may appear in the list of repositories in Gitweb, but users may see an error message if they try to access them.

 

Modifying Existing Repository Settings (update settings for an existing Git repository):

uapi --output=jsonpretty VersionControl update repository_root='/home/user/public_html/example'

This function only pulls changes from the remote repository if you specify a branch value. You cannot modify the type, repository_root, or URL values for existing repositories. You must include the repository_root parameter to identify the repository to update. All other input parameters are optional. Use them to assign the new values to the account. If you do not include a parameter or specify its existing value, no change will occur.

 

Creating a New Git Repository (create a new Git repository within the specified directory):

uapi --output=jsonpretty VersionControl create type='git' name='example' repository_root='/home/user/public_html/example'

type: Specifies the type of repository (e.g., git for Git repositories). name: The display name for the repository. repository_root: The absolute path to the directory where the repository will be stored.

If the directory does not exist, the system will create it. If the specified directory already contains a repository, the system will automatically add it to the list of cPanel-managed repositories. This feature also enforces several restrictions on repository paths.

 

Deleting a Git Repository (delete an existing Git repository and its contents):

uapi --output=jsonpretty VersionControl delete repository_root='/home/user/example'

repository_root: The absolute path to the directory containing the repository to be deleted.

Please note that when you call this function, the system permanently deletes the entire contents of the specified directory. You cannot recover this data after deletion. You also cannot use this function to delete any repositories that do not appear in the cache of repositories (for example, repositories that contain invalid characters or exist within cPanel-controlled directories).

 

Checking Deployment Status (retrieve status information for Git deployment tasks):

uapi --output=jsonpretty VersionControlDeployment retrieve

Creating a Deployment Task (create a deployment task to deploy changes from a Git repository):

uapi --output=jsonpretty VersionControlDeployment create repository_root='/home/user/public_html/example'

repository_root: The absolute path to the directory of the repository to be deployed.

 

Deleting a Deployment Task (delete a Git deployment task):

uapi --output=jsonpretty VersionControlDeployment delete deploy_id='13'

deploy_id: The ID of the deployment task to be deleted.

These commands enable you to perform various Git-related tasks programmatically via the cPanel API, enhancing automation and workflow efficiency within your WebHostingM environment.

By understanding these methods, you can leverage Git effectively within your WebHostingM cPanel environment.

For further assistance:

Did this answer help? 0 People found this helpful (0 Votes)