Svoboda | Graniru | BBC Russia | Golosameriki | Facebook
Skip to content

Creating a GitHub Repository from Existing Source Files

This guide shows you how to set up GitHub deployments on WordPress.com by starting with local source files. It assumes you have a GitHub account and set up Git on your computer.

Create a local Git repository

If you already have a local Git repository, you can skip this step and jump to Adding your files to GitHub.

I have a wp-env project

This is the official WordPress development environment based on Docker. This section assumes you have already set up a wp-env project. If you haven’t, you can follow this guide

Let’s assume you have created a new theme and plugin. Your project file structure will look something like this:

<project root>/wp-content/themes/mytheme
<project root>/wp-content/plugins/myplugin

or

<project root>/themes/mytheme
<project root>/plugins/myplugin
  1. At the <project root> in your terminal, run git init to create your Git repository.
  2. Next, run git add . to tell Git to start tracking your files.
  3. Then, run git commit -m “Initial commit” to commit your files.

You can now jump to Adding your files to GitHub.

I have a Local by Flywheel project

This guide shows you how to take a Local project and create a repository from the files you added. Sites created with Local contain a full WordPress installation. While you can add all of these to GitHub, it is recommended that you create the repository from only the files you added. 

Let’s assume you have created a new theme and plugin in your Local project. Your project file structure will look something like this:

public/...
public/wp-content/...
public/wp-content/themes/mytheme
public/wp-content/plugins/myplugin
  1. In Local, click Open site shell. The current working directory will be public, which is the site’s root folder.
  2. Run cd wp-content.
  3. Run git init to create your Git repository.
  4. Next, run git add themes/mytheme plugins/myplugin to tell Git to track your files.
  5. Finally, run git commit -m “Initial commit”

You can now jump to Adding your files to GitHub.

I have a wp-now project

This guide shows you how to take a wp-now project and create a local Git repository from it.

Let’s assume you created a plugin with wp-now and your files are in the current working directory:

index.php
style.css
  1. Run git init to create your Git repository.
  2. Next, run git add . to tell Git to track your files.
  3. Finally, run git commit -m “Initial commit”

You can now jump to Adding your files to GitHub.

I have files on my WordPress.com site

In this guide, we will use the rsync command. You can also copy your files to your local file system using an FTP client.

Let’s assume you have a custom theme on your WordPress.com site and wish to create a deployment for it. Your theme will be at:

/htdocs/wp-content/themes/mytheme
  1. Go to wordpress.com/hosting-config/:your-site and enable SSH if not already enabled.
The SSH access setting on WordPress.com with the SSH address and the toggle enabled
  1. Copy the SSH address, e.g. [email protected].
  2. Create a local folder by running mkdir myproject && cd myproject.
  3. Now copy your remote theme into your local project folder by running rsync -avzh SITE [email protected]:/htdocs/wp-content/themes/mytheme .. Make sure to change SITE NAME with your site name.
  4. You will need to enter your password, which you can get at wordpress.com/hosting-config/:your-site.
  5. Wait for the copy to complete, and then change directory into your theme folder by running cd mytheme.
  6. Then, run git init to create a Git repository.
  7. Next, run git add . to tell Git to track your files.
  8. Finally, run git commit -m “Initial commit”

You can now jump to Adding your files to GitHub.

Adding your files to GitHub

You should have a local Git repository before starting this step. We will create a repository on GitHub and push (upload) the contents of the local repository there.

  1. Navigate to https://github.com/new and
    • Enter a Repository name.
    • Choose Public or Private. If private, you will need to generate an access token before pushing your local repository to GitHub.
    • Important: Leave all other options as default. You can add a README and license later.
    • Click on the Create Repository button.
The 'Create a new repository' screen on GitHub with fields for Repository template, owner, repository name, and description.
  1. Take note of your GitHub repository URL, which will be https://github.com/<account name>/<repository name>.
  2. Back at the root of your project, run git remote add origin https://github.com/<account name>/<repository name>.git, which will link your local repository to your GitHub repository. Locally, your remote GitHub repository will be known as origin.
  3. Next, run git remote -v to verify it worked.
    • You should see something like:
origin https://github.com/<account name>/<repository name> (fetch)
origin https://github.com/<account name>/<repository name> (push)
  1. Now run git status and note the branch name you’re using.
  2. Run git push -u origin BRANCH with the branch name from the previous step.
  3. If your repository is private, create a new access token here.
    • Enter a value for Token name, select the repositories the token is valid for and then go to the Contents repository permission and select Read and write.
The Contents setting under 'personal access tokens' on GitHub with 'Access: read and write' selected
  1. Copy the access token from GitHub into the command line when prompted.
  2. Check GitHub and confirm your local files are now in your repository.

You can now jump to Setting up a WordPress.com deployment.

Links:

Setting up a WordPress.com deployment

Once you have your files in GitHub repository, you can continue with our GitHub Deployments guide.

Last updated: June 04, 2024