user3752231
user3752231

Reputation: 85

How to push code from Cloudways to Github

Is it possible to deploy code from a Cloudways app to an empty git repository? I would like to know if it's possible as I'm currently using FTP (Filezilla) for that. I'm able to clone a live site to a staging site, but cannot deploy it to Github in order to work on the files on my local machine.

Upvotes: 6

Views: 4565

Answers (3)

bart
bart

Reputation: 15298

First, create an empty repository on Github.com. Then log into your Cloudways dashboard, open your application and set up "Deployment via Git". When all that's done, open a command line application (eg. Terminal on Mac) and log in using your SSH credentials. Next up you'll be executing a handful of Git commands:

First, you need to turn your server code into a local repository, by running the git init command in the public_html directory. This creates a .git subdirectory, which contains all of the necessary metadata for the new repository. Next you create a snapshot using git add ., and then you use git commit -m "My Cloudways Repo" to capture the state of the snapshot. My Cloudways Repo is a message for this initial commit and can be anything. After that, set a new remote using git remote add origin [email protected]:username/name_of_repo.git, this is the same address you've used to setup "Deployment via Git". Finally, you use git push origin master to push the code to the remote Github server.

Summarized:

Using command line, navigate to your application folder: /home/master/applications/yourdomain.com/public_html then execute the following commands (one by one so you can read the responses):

git init
git add .
git commit -m "My Second Repo Cloudways"
git remote add origin [email protected]:username/name_of_repo.git
git push origin master

You can learn more about git init, git add and git commit here:

https://www.atlassian.com/git/tutorials/setting-up-a-repository https://www.cloudways.com/blog/wordpress-github/#create-repository-on-github

Upvotes: 6

farhan ayub
farhan ayub

Reputation: 60

First, you need to create a new repository on GitHub. Then, launch Cloudways SSH terminal (Server Management Panel > Master Credentials > Launch SSH Terminal) and paste your credentials. Now run these commands:

cd applications/xxxxxx/public_html. xxxxxx is a folder name.
git init
git add .
git checkout -b master
git commit -m "first commit"

If you see this message “Please tell me who you are”, then run these two commands

git config --global user.email "[email protected]" //                                                                                        
git config --global user.name "Your Name"


git remote add origin https://github.com/farhanayub/GitHub.git
git push origin master
Then insert GitHub username and password.

If you see any error then run the following and repeat the steps again.

rm -rf .git/

For your reference: https://www.cloudways.com/blog/wordpress-github/

Upvotes: 2

VonC
VonC

Reputation: 1329592

You should first make sure you can deploy your Cloudways application (that you have copied through filezilla locally) with Git, and pushed to a GitHub repo:
See "Deploy Code to Your Application Using Git".

Once your SSH access is setup, you can click "start deployment" to initiate the process. It will fetch the GitHub repo, and deploy it.

That means, to the question "Is it possible to deploy the code from a cloudways app to an empty git repository?": no, the publication process is the other way around.

That would involve:

  • Generating and downloading SSH keys
  • Uploading the SSH public key to your Git Repository
  • Copying the Repository SSH address
  • Deploying code from your Repository

The last step being:

  • Back on Cloudways console, paste the SSH address you got in Step 4 into the Git Remote Address field and click on the Authenticate. This will ensure that there are no blockers in the communication between Cloudways and Git service (which is Github in our example) .
  • Then choose the branch of your repository (master will be selected as default) you want to deploy from.
  • Next, type the deployment path (i.e. the folder in your server where the code will be deployed). Make sure to end it with a /.
    If you leave this field empty, the code will be deployed to public_html/.
  • Finally, click on the Start Deployment button to deploy your code to the selected path.

https://support.cloudways.com/wp-content/uploads/2018/03/git-deploy-new1.png

Upvotes: 2

Related Questions