Hosting a GitHub repository on a web server (Auto deployment)

If you’ve ever hosted a website before, FTP is nice, but can be cumbersome when trying to add or remove many files at once or trying to configure servers and credentials. A good alternative to this is to auto deploy a GitHub repository to the www directory of your web server, so that any changes that are made the repository are automatically pulled and go live immediately with no extra steps. 🤯

Make a GitHub Repository

To begin, you’ll need a GitHub repository where you’ll keep all the files for your site. You can go to github.com and create a repository there. This will work on public and private repositories.

Making and Managing a Deploy Key

Once you have made your repository, you will need to access your remote web server. We will be using an SSH key to provide access to the repo. You can generate one with the command ( ⚠️ replacing respective values):

$ ssh-keygen -t rsa -b 4096 -C "your email address here"

When prompted for a location, you can press Enter to use the default location. You may optionally add a passphrase in this setup. Just ensure you write it down.

You can now run the command to view the public key:

$ cat ~/.ssh/id_rsa.pub

Copy the result from the terminal.

Next, open your repository’s GitHub page and go to Settings → Deploy Keys. Here, click Add Deploy Key. For Title, choose as you please. Paste the previously copied key into the Key field. You will want to check Allow write access. Hit Add key.

Initializing GitHub Repository

Back in the terminal, navigate to your site files (or where you want them to appear). Run these commands ( ⚠️ replace values respectively):

$ git config --global user.email "you@example.com"
$ git config --global user.name "Your Name"

The next step depends on whether you have your files here already, or you don’t.

I already have my files on the server! Great! Run these commands ( ⚠️ ensure you replace user and repo with their respective values):

$ git init
$ git add *
$ git commit -m "add site files" 
$ git remote add origin git@github.com:{user}/{repo}.git
$ git push -u origin master 

I don’t have my files on the server! Great! Run these commands ( ⚠️ ensure you replace user and repo with their respective values):

$ echo "# a fancy title" >> README.md
$ git init
$ git add README.md
$ git commit -m "first commit"
$ git remote add origin git@github.com:{user}/{repo}.git 
$ git push -u origin master

Great! Check your GitHub page to see your file(s).

Auto-Deployment

Ooh… this is the scary part. 👻 You’ll need PHP and be able to make a shell_exec command. In your www directory, run this command:

$ nano gitpull.php

And paste the following code (⚠️ adjust the path if necessary):

<?php
echo shell_exec("cd ~/public_html && git pull origin master 2>&1");

You could expand this code to require a key, if you deem necessary.

Then press Ctrl+O, Enter, then Ctrl+X to save. This PHP script will pull from the master branch of the repository when called and return the response of the git command.

Final steps!!1 Head back to the GitHub repository page and hit Actions, then Setup a workflow yourself. Copy and paste the below code ( ⚠️ replacing respective values):

name: auto-deploy-amazingness
 on:
   push:
     branches: [ master ]
   pull_request:
     branches: [ master ]
 jobs:
   build:
     runs-on: ubuntu-latest
     steps:
     - uses: actions/checkout@v2
     - name: Git pull via GET
       run: |
         curl -i -H "Accept: application/json" -H "Content-Type: application/json" https://{yourdomain}/gitpull.php

Then, hit Start Commit, then Commit new file.

Phew, all done! 🎉 You’ll notice either a green check mark next to the latest commit on the GitHub repository page if it has processed, or a yellow circle if it is still processing. This will automatically deploy your GitHub repository on every commit. 😎👏

The CubeSolver Electric

In our latest product, the CubeSolver Electric, the device can solve your cube in approximately 10 seconds, flawlessly. It uses a simple timer on your phone with the device to change the color of the stickers with electricity.

Don’t believe it works? Watch the full video for a mathematical proof. It uses calculus to accurately define the way the CubeSolver Electric works.