Trouble pushing Git Sub Modules to server- Using Post Receive hook. - wordpress

I've spent a few weeks on this one, and I'm finally giving in and asking for help. I think I've tried just about every method I've seen suggested in other posts and tutorials, however nothing seems to be working. Anyways, here is my setup-
I have a git repository stored on BitBucket that is my local repo. I want to push my changes to my remote production server (and also staging), but for now lets focus on making one work. The way I have the remote server set up is by using a post-receive hook outside of my public_html folder. The folder is called repos and the bare repo is called development.git. The post receive hook inside repos/development.git is simple enough-
#!/bin/sh
GIT_WORK_TREE=/home/peterj05/public_html git checkout -f
I added the production server as a remote inside my local repo as "production" and push to /myserversaddress/repos/development.git, and the post-receive hook then transfers it to my public_html folder where I want it. The problem is that I have Wordpress added as a submodule and that the submodule does not get pushed along with everything else.
I've tried adding
git submodule init
git submodule update
to no avail.I've also tried some other methods, but either I'm screwing things up (which is entirely possible. While I'm not new to Git, I'm no expert by any means, and sometimes need things spelled out for me). Deployment options especially are new to me, which is why a lot of this has been so hard.
I'm willing to try just about any method, other than the pay service deployment options out there.
I'm at the end of my rope here. I've read so much and nothing seems to be working. I have to be missing something here. I am also pushing recursively in case anyone is wondering.
-P.J.

Related

Keeping a custom theme up to date with upstream

My team will be working on a Wordpress project (theme), and we're looking to build using the Foundation CSS framework. Additionally, we will be making use of Git as source control.
We've discovered the Foundationpress theme, and would like to use it as a starting point: https://github.com/olefredrik/FoundationPress
We would only want to do this once in a while, ie maybe there is a bug in the current version that gets fixed.
My question is, how can we keep up to date with changes to the Foundationpress theme selectively?
ie: Should I fork the project, and change the remote origin to our Github repository, and add a secondary remote for the Foundationpress repo, and then only pull down changes from the Foundationpress remote when needed? I'm just not really sure what the best practice is.
Maybe there's a better way to handle this entirely. Thank you!
Even if you fork the olefredrik/FoundationPress, your fork repo will not contain the update changes that olefredrik/FoundationPress made.
If you don’t need to contribute for olefredrik/FoundationPress, and you already have your own remote repo you want to work on, you can directly add remote by git remote add upstream https://github.com/olefredrik/FoundationPress.git, and check if there has update by
git fetch upstream
git log master..upstream/master
If there has output, that means olefredrik/FoundationPress has new commit(s) which is(are) not contains in your local repo. You can use git pull upstream master to pull the new changes.
If you need to contribute for olefredrik/FoundationPress or you don’t have your own remote repo, so you can fork it and check if there has update changes by the same way above.

Quick and easy version control for WordPress Themes?

I work alongside two other developers and we seriously need a method of version control implementing within our workflow. Currently we're centralising data using a Synology NAS (which is backing itself up to Google Drive) but the bulk of our development work is done on our local machines just to speed things up.
We've been running into issues lately where we have lost track of file versions when moving between local, centralised and live copies due to our set up. We have suggested, between ourselves, using Git but none of us are experienced with it and after spending today doing some research I feel as though it is not going to actually help. It feels quite clunky and as though it slows the process down. Maybe I'm just doing something wrong?
Anyway, if anybody could suggest a better way/optimal git config they have used or had experience with I would be greatly appreciative.
Thanks in advance,
Ethan.
If you don't want to use git, then I suggest to use SVN. You can find a free SVN repository here: https://riouxsvn.com/
Hope it works!
Preparation to use git to version control your WordPress theme:
1. Remote repo. This is the place where the versions to be managed and controlled. You can create a remote repo by git init --bared. Or you can use github, bitbuckte etc to host your remote repo.
2. Local repo. make changes the develop on it. You can use below commands to work with your remote repo:
git clone /path/to/remote/repo
git add filename #after you add/modify a file
git commit -m 'message' #commit your changes in local repo
git push #push your local changes to remote repo
More details about git, you can refer git book .

Git Siteground Deployment WordPress Sublime Text

I am a beginning developer looking to get a great workflow setup before I begin my personal website: kevinbmccall.com
The site has WordPress installed and is hosted by SiteGround.
I enjoy the Sublime Text 3 Editor and am looking to emulate the workflow described here: http://joshuaiz.com/words/the-ultimate-workflow/
I was already in the process of learning Git through the terminal and had a GitHub repo setup through a local project folder. So I didn't really follow Joshua exactly and may have been what led me to get stuck but I think I got to the SSH part.
Here is what I have done so far:
Installed Sublime Text 3 with SublimeGit Package
Installed Wordpress on kevinbmccall.com
Deleted all files from local projects/kevinbmccall folder with git
Copied all files from siteground server to local folder
Added and Committed all of these changes to github repo
Tried Adding PHP Script to siteground server and setting up webhook
Issue: "I want the server to sync with my github repo so I can easily deploy to my live site every time I push to github"
Here is what I can do now:
I can make local changes to my project folder, add them and commit them no problem.
This correctly updates my github repo fine but does not seem to deploy yet.
If I make a change to my local folder, add, commit and check the status it will tell me of an origin/master that is behind in commits and recommends a push
I can push and even see some sort of request triggered because of that attempt at a PHP script I think but I was hoping to see the test txt files show up on the server and they did not.
My Thoughts:
I think my issue has to do with writing to the server and maybe the SSH setup through Siteground. I generated a key but never really used it and all of the online material from siteground points to their SG-Git tool in the c-panel. This requires a more expensive monthly plan and I am just a beginning developer trying to get a personal site up. I am sure the deployment can be accomplished without this upgrade.
Thank you to whomever replies. My goal is to learn as much as possible so I am even more interested in the explanation than the solution.
In my opinion, maybe you need GitHub Webhooks.
This is a demo
// Init vars
$LOCAL_ROOT = "/var/www/my_new_site";
$LOCAL_REPO_NAME = "public_html";
$LOCAL_REPO = "{$LOCAL_ROOT}/{$LOCAL_REPO_NAME}";
$REMOTE_REPO = "git#github.com:jonathanstark/my_new_site.git";
$DESIRED_BRANCH = "dev";
// Delete local repo if it exists
if (file_exists($LOCAL_REPO)) {
shell_exec("rm -rf {$LOCAL_REPO}");
}
// Clone fresh repo from github using desired local repo name and checkout the desired branch
echo shell_exec("cd {$LOCAL_ROOT} && git clone {$REMOTE_REPO} {$LOCAL_REPO_NAME} && cd {$LOCAL_REPO} && git checkout {$BRANCH}");
die("done " . mktime());

Git pull from heroku

How do I pull from heroku?
I have wordpress running in my heroku app and i changed some stuff via the template editor.
I'd like to have these changes also locally.
When i try to pull from heroku i get the message:
Already up-to-date.
But I don't have these changes locally
It's normal to get the Already up-to-date message, since the remote changes weren't commit and pushed.
Since you cannot commit and push from Heroku, you need work locally and then deploy. And that's how you should work at first place.
What did you change with the template editor? Probably configuration, and not code right? So if you do a pull from Heroku, you're not going to see changes? (I'm not familiar with wordpress - but I doubt the template changes result in code changes). So I guess I'm hypothesising that it's right: there are no changes.
Perhaps what you really want are database changes?
By the way, you can now clone a Heroku app with the new heroku git:clone
What does git branch -r --no-merged return? If it returns any branches, it means those branches have changes you don't have in the current branch yet. Merge them to get the changes.
Otherwise, the thing you are pulling does indeed not have any changes. That can mean that the changes you are looking for in another branch.
What you might want to do in that case is git fetch <heroku> where heroku is the name of the remote pointing to the heroku repository. That'll fetch all banches from heroku, which you then are able to merge.

How to develop using GIT on database driven website project?

I like to use a simple Git workflow for static web sites but I build Joomla and Wordpress sites a semi-regular basis too. However I am at a loss as to how to use Git with with database driven site development.
For a static site I would 'Push' to dev.websitename.com, then push to www.websitename.com once the dev site checks out. How would I mimic that process with database driven site like wordpress or joomla.
Thanks in advance for you insight!
You can definitely use Git with your website code, such as changes to your WordPress theme/plugin, exactly as you would if you are developing a static website.
However, you wouldn't use it for your database. Git provides version control for code, while WordPress and Joomla already manage content stored in the database. Plus, Git wouldn't understand a database, so it wouldn't have any advantage over a periodic backup, which you should already be doing. Take a look at running a dev copy of your site for how to download your database directly from your server.
By the way, if you use Git with WordPress/Joomla, you should add e.g. cache, logs, tmp to .gitignore. There are also lots of tutorials out there--try searching e.g. http://google.com/search?q=wordpress+git.
In addition Chris, you may want to embark on your Git workflow without the handy script approach (at least initially). The script approach and using Git hooks can sure seem sexy (well, because they are) and handy too, but initially why not go with a more manual cmd line approach, which will also help you familiarize yourself with Git.
Once you've got your repo setup (GitHub, Bitbucket, somewhere else) and you've pushed your latest to it and are ready to deploy to production or staging, just login to your host and from wherever you've initialized the git repo (site root, example: /site) just do a:
git pull origin master
This will fetch and merge your code. Good idea to test this on a dev/staging environment and if the merge goes well then do it in production.

Resources