Version control is currently part of any coding project. The most used hosting tool for that purpose, Github, currently has a very straightforward process, but some intrincated tutorials still leave those who are starting on plugin dev in the dark.

So, let’s make it as easy as possible, and leave any particular detail for future posts. In this article, we will focus on a simple step by step:

  • Create a starter plugin in our own local machine
  • Create a repository on Github, in which the code will be hosted
  • Establish a connection between the local repo and the Github’s repo

Ready? So open the terminal and let’s work.

Creating a starter plugin

Here you can keep you usual practices. In my case, I would prefer to start any new plugin project by using WP-CLI. The command scaffold do the job and create a new skeleton plugin without any fancy structure or package.

1/12 <slug>: 
2/12 [--dir=<dirname>]: 
3/12 [--plugin_name=<title>]: 
4/12 [--plugin_description=<description>]: 
5/12 [--plugin_author=<author>]: 
6/12 [--plugin_author_uri=<url>]: 
7/12 [--plugin_uri=<url>]: 
8/12 [--skip-tests] (Y/n): y
9/12 [--ci=<provider>]: 
10/12 [--activate] (Y/n): n
11/12 [--activate-network] (Y/n): n
12/12 [--force] (Y/n): 

All you need to do is filling the questions – remember that you probably want your plugin folder to be located inside the plugins folder, so in 2/12 you need to indicate the plugins directory, if you are in the wp-content folder, or pointing the equivalent path.

Depending on the plugin slug, a folder and the following files will be automatically created (here I skipped the tests):

  • plugin-slug.php is the main PHP plugin file.
  • readme.txt is the readme file for the plugin.
  • package.json needed by NPM holds various metadata relevant to the project. Packages: gruntgrunt-wp-i18n and grunt-wp-readme-to-markdown. Scripts: startreadmei18n.
  • Gruntfile.js is the JS file containing Grunt tasks. Tasks: i18n containing addtextdomain and makepotreadme containing wp_readme_to_markdown.
  • .editorconfig is the configuration file for Editor.
  • .gitignore tells which files (or patterns) git should ignore.
  • .distignore tells which files and folders should be ignored in distribution.

As we are not interested in properly develop a plugin for this article, let’s now leave the newly-created scaffold and move to the next step.

Creating a repo on Github

Well, before anything else, if you don’t have an account on Github, it’s time for you to sign up. If necessary, set up a new account and then we can work the next tasks.

Keep your terminal in the plugin project folder, and in the browser, open the dashboard on your Github account. Top, and left, you probably can see a list of repos (empty, as you are just starting with it), and a small button “NEW”, for adding new repositories. Click on that green button.

In the next step, you need to name the repo, provide a short description, if you want, and set by now the repository as public, and skip all other options (we are generating the README and .gitignore files afterwards).

Now just scroll down and click the button “Create Repository”.

Connecting your project

Now you have a repo created on Github, let’s go back to your terminal. In your project’s folder, follow the commands below:

echo "# fdgdfdgfdd" >> # Creates a README file
git init # Starts Git version control in your project
git add . # Adds all existent files to Git
git commit -m "first commit" # Commits changes
git branch -M main # Determines a branch name
git remote add origin # Connects to Github's remote repository
git push -u origin main # Pushes the last commit to Github

Now check your repository on Github and you’ll see that all files existent in your local computer have been pushed to the remote repo.

That’s it. Now, everytime you want to update changes and generate a new version on Github’s repo, all you need to do is repeat the lines of git add, git commit (changing the description) and git push in the previous Bash commands.

In some next posts, we will explore more advanced uses of Git while developing WP plugins or themes.