This website uses cookies

Our website, platform and/or any sub domains use cookies to understand how you use our services, and to improve both your experience and our marketing relevance.

This website uses cookies

Our website, platform and/or any sub domains use cookies to understand how you use our services, and to improve both your experience and our marketing relevance.

Introducing Cloudways Community Forum. Start Discussions and Get Instant Help From Cloudways Community. JOIN NOW
Enhance your managed hosting experience with fast performance, 24x7 support and managed security. Start for Free

Using Git via Command LineJune 29, 2017


In this KB

  • Generate SSH keys
  • Upload SSH Public key to your Git Repository
  • Deploy Code using Git Command (via master credentials)
  • Important Notes


This guide will assist you on how to deploy code to your application using Git commands.

Remember that you can deploy your Git code (pull) using the Cloudways console (refer to this guide). However, if you want to use other Git functionalities (such as push, pull, clone, etc), you will need to access your server through SSH.

Note: You need Master Credentials to run Git commands because Application Credentials do not have permission to generate and access SSH keys (stored in the default location). If you are a team member, you can use Git deployment via Cloudways Platform (or request master credential access from the account owner).

Step 1: Get SSH Access

Connect to your server via SSH. (To do this please, follow this guide.)

Step 2: Generate SSH Key (Master Credentials Only)

Once the SSH connection has been established, you need to generate SSH keys for directly connecting your GitHub or Bitbucket repositories without providing a username or password every time

Navigate to your desired web application’s webroot (public_html) and then type the following command to generate public and private RSA key pair.

Hit Enter to save the key in the default location (/home/master/.ssh/id_rsa). Hit Enter twice for no/empty passphrase.

Your SSH keys will be saved at the default location. Run the following command to view the generated public SSH key.

Copy the public key text carefully starting from ssh-rsa and ending in your email address. This text will be used in the next step.

SSH Access

Step 3: Upload the SSH Public Key to Your Git Repository

We are using a Github account for this demonstration. If you prefer another Git service, you will have to find the equivalent way of completing this step.

Log into your GitHub account and choose your desired repository (which you want to connect to your web application).  Then, navigate to Settings and click on Deploy Keys.

  1. Click on Add Deploy Key button to add the SSH key we copied in step 3. Paste the content into the Key field on Github. You can give a name to this key in the title field (e.g. Demo).
  2. Check Allow write access option to give write access (push) to your repository
  3. Click on Add Key button to save the SSH key.

Github Deploy SSH Keys

Step 4: Deploy Code Using Git Commands

After successful addition of the SSH key to the GitHub repository, you can now execute Git commands on your server (under the application’s public_html or private_html) using the shell access with Master Credentials.

Some useful Git commands are mentioned below:

Git Clone: To get a copy of the code (web files) from the GitHub repository, use the following command.

Git init: Use the following command to initialize a local Git repository.

Git add: Add the files to your new local repository.

Git commit: Commit the files that you want to stage in the local Git repository.

Git remote add: Run the following command to add the Git URL where your local repository will be pushed.

Verify Git remote URL:

Git push: Push changes in your local repository to your GitHub.

Git checkout: You can create a branch and switch to it by running the following command.

Or, if the branch has already been created, then:

Git merge: You can merge the branch into the master branch through the following command:

Important Notes:

  • SSH keys generated from Cloudways UI will work for Git deployments from the console only. Therefore, you will have to generate SSH keys (via Master Credentials) on your server through SSH in order to run Git commands.
  • You can upload the same key (public) to your other Git repositories that you want to connect to your web applications hosted on the same server, for the purpose of granting permission to run Git commands.
  • Git remote address added via SSH will work for both pulling (deploying) and pushing (uploading) your code from/to the remote repository.
  • If you want to automate your Git deployments on Cloudways, please refer to this guide.
Please insert Content
Have Questions? Ask From Our Helpful Community

Comments are closed.

Do you still need help?

Our Technical Support team is always at work.