How to install from git

Ok, I’m trying to build a serious relationship with GitHub :rofl:
I’ve created a repository for a plugin. Then moved in the plugin folder on my server.
Now the plugin is there and I’ve learned how to reflect changes.

Is there a way I can install, possibly with wp-cli, the plugin in another site?

The plugin is here.
Thank you very much!

1 Like

Easy one-time way

Copy the URL of this “Download ZIP” link, then…

$ wp plugin install https://github.com/xxsimoxx/cpcompatibility/archive/master.zip
Downloading installation package from https://github.com/xxsimoxx/cpcompatibility/archive/master.zip...
Unpacking the package...
Installing the plugin...
Renamed Github-based project from 'cpcompatibility-master' to 'cpcompatibility'.
Plugin installed successfully.
Success: Installed 1 of 1 plugins.

I am not sure the best way to keep the plugin up to date after this.

Using git instead

cd wp-content/plugins
git clone https://github.com/xxsimoxx/cpcompatibility

When you’re ready to update the plugin:

cd wp-content/plugins/cpcompatibility
git pull origin master

git pull will work most of the time, but here is a slightly more foolproof alternative (this will try harder to overwrite any local changes and make your copy the same as what’s on the remote repository, in this case GitHub):

git fetch origin
git checkout origin/master -B master

You can also develop against this copy of the plugin, git add and git commit your changes, and then git push them to GitHub. I usually develop plugins using some variation of this technique (a git repository inside of a working site).

This is the option I would recommend, it is more complicated but also much more flexible, and you will start to learn more about how git works if you don’t already know.

5 Likes

Thank you very much!
Simone.

1 Like

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.

Once you’ve mastered that, you’ll appreciate putting your entire (site-specific; non-ClassicPress core files… and also not uploads dir) site in git for easy deployment and change tracking.

But soft, what file tracking through yonder nested repo breaks?

Yeah, cloning a repo (such as your plugin) within a repo (such as your main site) can be a mess, which is where git submodules come into play.

# Add the plugin as a submodule
cd /path/to/wp-content/plugins
git submodule add https://github.com/xxsimoxx/cpcompatibility

# Pull from repo to another site
git pull --recurse-submodules
git submodule update --init --recursive --remote

(I had links in this post for you to reference, but this garbage won’t let me include links in my post.)

5 Likes

This “garbage” is set so new members don’t rank enough to post links, sorry. This is done so to understand if new members are serious about participating. In your case, since your contribution is valuable, I think continuing to stick around you’ll soon get higher rank.

3 Likes

I usually put the whole site including the core files under version control in a single repository. Not the uploads directory though.

I also try to avoid submodules generally, but this would be a good way to keep the benefits of a git repository for specific plugins and also a main repository for the site.

2 Likes

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.