All I wanted to do was setup a new WordPress site, host the code with GitHub, and use a code editor to make edits to the WordPress template. In the world of building websites, this has to be incredibly common. Unfortunately, I couldn’t find any instructions online that outlined how to do this. I also reached out to my hosting provider, and they weren’t able to help me either (even though we went back and forth about 10 times). I eventually just figured it out, which lead to much rejoicing. Afterward, I decided to write down the steps I had taken to accomplish this task, so I wouldn’t forget in the future. During this process, I realized why I was having so much trouble- the words that are used to describe everything that you do related to servers and hosting are absolutely RIDICULOUS!
SSH, https clone, git, push & pull (not with your hands), commit, stage, remote repository, IDE
You need to know what all of those things are and what they mean in order to even ask a question about server admin. You’ll also need to know commands like “git push origin master” and “ssh add.” The whole thing is just absurd.
Anyway, for anyone that is interested, here are my notes of how I finally accomplished the task (at least this is my best recollection of the process):
Getting WordPress site on Github using a Mac with Terminal- Notes
- Setup hosting account
- Setup GitHub account
- Setup SSH
- Go to SSH/Shell Panel on cPanel to create the SSH pair
- Generate a new SSH pair
- Store password that you add when creating the SSH pair (you’ll need this to login to SSH)
- Enter the IP address of the Mac for “allowed IP address” (you can add additional IP addresses to the SSH pair, if the IP address changes)
- Follow these instructions to login to the site using SSH for Siteground: http://kb.siteground.com/How_to_log_in_to_my_shared_account_via_SSH_in_Mac_OS/
- The port number will likely be different with other hosting companies
- Once you are logged in using SSH, you will be able to access files and run commands on the server via Terminal
- Add the code from the hosting account to the GitHub repository
- Create a new GitHub repository and don’t add the ReadMe txt file (leave the new repository empty)
- Notice the “https clone URL” (not the SSH URL or subversion checkout URL) from the GitHub repository to your Mac clipboard (you’ll need it in a minute). You can find the URL on pretty much any page of the repository. It’s called the “https clone URL” and it looks like this: https://github.com/[account]/[repository]
- Login to your server through Terminal using SSH (this is how to do it with SiteGround- the port number will likely be different for other hosting companies: http://kb.siteground.com/how_to_log_in_to_my_shared_account_via_ssh_in_mac_os/
- Once you have logged into your server, navigate to the public_html folder (you might type something like this: “cd public_folder” to get there).
to initialize the public_folder for git
git add .
to add the files for and stages them for commit
git commit -m 'First commit'
commits the files in the public_folder and prepares them to be pushed to the repository
- These instructions are typically talking about adding files from your local project, but I’ve just swapped to add files from the server to the repository
To access and or modify files on your local computer, you can either install GitHub desktop and use the “Clone in Desktop” button that you’ll find in the GitHub repository (on the website) or install an IDE (like Eclipse, WebStorm, PHPStorm or IntelliJ IDEA and add using the Git (often found under the VCS menu or under File/ Add New Project from Version Control- you’ll once again need the “https clone URL” to connect the IDE to GitHub.
In order to push changes from GitHub desktop or the IDE, you’ll need to both commit the changes that you make and push them to GitHub. Then you’ll need to use Terminal to connect via SSH to your server and type the command “git pull origin master” then enter your GitHub username and your GitHub password. The changes will then appear on the server.