Push Your WordPress Theme from Your Server to Your GitHub Account
Using version control like Git with WordPress can greatly improve your workflow, especially when dealing with large scale projects. While developing locally and then pushing files to GitHub is pretty straightforward with GitHub’s native apps for Windows and Mac, developers will often find themselves working on a client’s production server. In situations like these, knowing how to push files from a server to GitHub can be a valuable tool.
For this tutorial, we will be focusing on pushing a WordPress theme, Twenty Fourteen, from your web server to a GitHub repository. This tutorial is for those who are new to Git/GitHub but assumes that you know how to use SSH to access your server. If you’re not sure if SSH is enabled on your server, contact your host and they should be able to enable it for you.
Setting Up Git In The Theme Folder
- Open up your SSH client (I use PuTTY) and connect to your server.
- Double check that your host has Git enabled on the server by typing
- Now we want to take the terminal to the correct directory of our server. In this case, we want to go to our theme folder. In order to do this we use the Change Directory command (cd). For example, if you want to go to the twentyfourteen theme folder on your server you would enter the path to the folder, such as:
- Assuming you are doing this for the first time, you will have to initialize a git repo in the theme folder. To check if a git repository already exists in your theme folder, simply enter
in the command line. If no git repo exists, you will get a fatal error.
- To create a new git repo in your theme folder, enter
You will see a message that says “Initialized empty Git repository in [path to theme folder]”
- Now, let’s put the README file in the theme directory for GitHub to read. Do this by entering
There should now be README file in your theme folder on your server.
- Now, if you enter
you will see a list of all the files that are only in the root of the theme folder. We want to add all files from the theme folder and its subfolders to the repo. To do this, type
git add *
Now if you enter
you will see all the files in the sub-folders of your theme as well.
Setting Up Your Repository On GitHub
- First, login to your github account and create a new repository.
- For our example, let’s call our new repository “twentyfourteen”. Choose whether or not the repo will be public or private (private repos are only for paid accounts). Do not check the box that says “Initialize this repository with a README” since we have already created one. Click “Create repository” when ready.
The page that follows will give you some very helpful information for creating your first commit.
- Under the “Create a new repository on the command line” heading, copy the final 3 commands into the command line. The final 3 commands are:
git commit -m "first commit"
This command creates the note that will go along with the commit
git remote add origin [email protected]:YOURUSERNAMEHERE/twentyfourteen.git
This command tells Git where we are going to be pushing this commit to. In this case, we are pushing to our specific repo in github.
git push -u origin master
This command actually pushes your files to your Github account.
- Now if you go to your GitHub account, you will see that your twentyfourteen repo has all of your theme files and folders.
Now let’s see what happens when we update a file in the theme folder on our server.
- The README file in the twentyfourteen folder should be empty, so open it up via your FTP client, add the following line, and save the file:
“Thanks for reading this README file!”
- Back in the console, type
you should see a line that says the README file has been modified
- Add the README file to the commit by typing
git add *
- Add a note to the commit using the commit command we used earlier:
git commit -m "just updated the README"
- And now push the commit using the same command as before:
git push origin master
Using this method you can quickly and easily use the power of Git and the convenience of GitHub in your next WordPress theme development project.