How to Upload to Git via Terminal Line

This guide will assist yous in how to deploy code to your application using Git commands.

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

Important

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 admission from the business relationship owner).

Using Git via Control Line

Step 1: Get SSH Admission

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

Step ii: Generate SSH Key (Principal Credentials Only)

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

Navigate to your desired spider web application's webroot (public_html) then type the post-obit command to generate public and private RSA key pair.

          ssh-keygen -t rsa -C your_email@case.com
#replace your_email@example.com with your electronic mail address.

Hit Enter to salvage the key in the default location (/home/chief/.ssh/id_rsa). Hitting 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.

          cat /home/chief/.ssh/id_rsa.pub        

Copy the public key text advisedly starting from ssh-rsa and catastrophe in your email address. This text volition be used in the next step.

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

We are using a Github account for this sit-in. If you lot prefer another Git service, you volition have to find the equivalent way of completing this stride.

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 Central button to add the SSH key we copied in pace 3. Paste the content into the Cardinal field on Github. You can give a name to this key in the title field (e.g. Demo).

  2. Bank check Allow write access option to requite write access (push) to your repository

  3. Click on Add Key push button to save the SSH key.

Stride 4: Deploy Code Using Git Commands

Subsequently successful addition of the SSH key to the GitHub repository, you lot tin can now execute Git commands on your server (under the awarding'south public_html or private_html) using the vanquish access with Master Credentials.

Some useful Git commands are mentioned below:

Git Clone: To become a copy of the lawmaking (spider web files) from the GitHub repository, employ the following command.

          $ git clone git_url            
#replace git_url with your repository, for example git@github.com:cloudwaystestdemo.git

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

          $ git init        

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

          $ git add . #Adds the files to the local repository and stages them for commit.        

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

          $ git commit -k "my commencement git commit."
#Commits the tracked changes and prepares them to to be pushed to a remote Git repository.

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

          $ git remote add origin remote_repository_SSH_URL
#adds the new remote

Verify Git remote URL:

          $ git remote -5        

Git push button: Button changes in your local repository to your GitHub.

          $ git push origin master
#pushes the changes in the local repository to the remote repository yous added as the origin

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

          $ git checkout -b branchname        

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

          $ git checkout branchname        

Git merge: You can merge the co-operative into the primary co-operative through the following command:

          $ git merge master        

Important Notes

  • SSH keys generated from Cloudways UI will piece of work for Git deployments from the panel only. Therefore, you will have to generate SSH keys (via Master Credentials) on your server through SSH in gild to run Git commands.

  • You lot tin upload the same fundamental (public) to your other Git repositories that you want to connect to your spider web applications hosted on the same server, for the purpose of granting permission to run Git commands.

  • Git remote address added via SSH volition piece of work for both pulling (deploying) and pushing (uploading) your lawmaking from/to the remote repository.

  • If yous want to automate your Git deployments on Cloudways, please refer to this guide.

That'due south it! Nosotros promise this article was helpful. If yous need any aid, then feel complimentary to search your query on Cloudways Support Heart or contact united states via chat (Need a Hand > Send us a Message). Alternatively, yous tin can also create a support ticket.

bemiscaloque.blogspot.com

Source: https://support.cloudways.com/en/articles/5124793-using-git-via-command-line

0 Response to "How to Upload to Git via Terminal Line"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel