Separating Wordpress theme from system files in a git repository - wordpress

I've been making a Wordpress theme and using git to save progress. My whole Wordpress site is in the git project, and I would like to remove everything except the theme folder so I can easily transplant it on other Wordpress sites.
I know one way is to just delete everything and move the theme to the root folder and commit. But checking out after that will be more complicated, right? So is there another way?
Thanks.

If you are interested in keeping the full history of your Theme folder, you can use git filter-branch and remove everything else.
See "Extract part of a git repository?" ,to be done in a clone of your current repo:
git filter-branch --subdirectory-filter Project/SubProject-0 --prune-empty -- --all

Related

Moving the Git Repository to a Child Folder

I'm using Github with my Wordpress website.
Currently it tracks the parent Wordpress folder, which essentially tracks everything.
I'd like it instead to have a git with only the theme, which is located at wp-content/themes/lighthouse
Is there a simple way to have this repository only be the theme rather than everything in Wordpress? Without having to make a new repository?
If you really don't want to create a new repo, you would simply delete the other folders, and push that new (trimmed) commit back to your existing repo.
Note that you would conserve the other folders history in your past commits.
The techniques mentioned in "Detach (move) subdirectory into separate Git repository" would in effect create a new repo (one with an history only involving the folder you want to keep)
To move git repo to subfolder wp-content/themes/lighthouse while keeping the subfolder’s history, you can refer below steps:
git clone <repo URL>
cd reponame
# checkout all the remote branches locally by git checkout branchname
git filter-branch --subdirectory-filter wp-content/themes/lighthouse -- --all
git push -f --all
Now the git repo moves to the subfolder wp-content/themes/lighthouse and keeps the related histories

Excluding files from localgit repo

I am working on a Wordpress site, and been given access to the git repository for this project. The entire WP install is in the Repo. All I care about is being able to push my changes to the theme and a select list of plugin folders, ie:
/wp-content/themes/myTheme2017/
/wp-content/plugins/myPlugin1/
/wp-content/plugins/myPlugin2/
....
How can I exclude everything else from being tracked? How can I update my local WP install, and customize my wp-config.php file, and not have those changes be tracked?
As per How do I configure git to ignore some files locally?, I can specify the files I want excluded much like in gitignore files. Then, I can run git update-index --skip-worktree [<file>...] and get my desired results.
git update-index --skip-worktree wp-config.php
The real question is then can I exclude entire folders? Do I have to run the skip-worktree command on every file?
The real question is then can I exclude entire folders? Do I have to run the skip-worktree command on every file?
Yes, every file: Git does work with content (files), not containers (directories).
You can find here an approach using submodules
git submodule add -f https://github.com/wp-plugins/wp-migrate-db.git ./wp-content/plugins/wp-migrate-db
git commit -m "Added WP Migrate DB plugin"
That allows to commit separately in your parent repo or your submodule.

What causes a fatal: not a git repository error?

I am working on webpage, and I need version tracking, so I'm uploading it to github.
Here is the underlying set up.
https://developers.google.com/appengine/articles/wordpress
Now that I have the base CMS ready to go, I need to get the base code uploaded before I start making changes.
lloydm#lloydm-E6320:~/Downloads/rtt/rtt-code$ pwd
/home/lloydm/Downloads/rtt/rtt-code
lloydm#lloydm-E6320:~/Downloads/rtt/rtt-code$ git status
# On branch master
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# wordpress/
nothing added to commit but untracked files present (use "git add" to track)
lloydm#lloydm-E6320:~/Downloads/rtt/rtt-code$ ls
app.yaml cron.yaml php.ini wordpress
lloydm#lloydm-E6320:~/Downloads/rtt/rtt-code$ git add .
fatal: Not a git repository: wordpress/wp-content/plugins/../.git/modules/appengine-wordpress-plugin
I've never used github before, so I was just following the github website stuff. I have zero idea what this error means or how to prevent it. I can't find anything that I think is related to it.
You need to set up your git repo correctly.
I think you followed this section "Installing WordPress on your development environment" from the link you provided https://developers.google.com/appengine/articles/wordpress
So what you did was download WordPress into your folder which you set up to be a .git repository. However, the WordPress project builder you downloaded itself contains a .git repository.
Check if you have a /workpress/.git file. It likely contains something like :
gitdir: ../.git/modules/wordpress
If you do, then that explains the error I think.
As for setting it up correctly, there are many tutorials available.
One way is to use Git for theme deployment, rather than having it manage your entire WordPress installation --> http://culttt.com/2013/04/08/how-to-deploy-wordpress-themes-with-git/
Another way is to add wordpress as a submodule http://www.efeqdev.com/website-development/this-is-how-we-version-control-and-deploy-our-wordpress-websites-with-git/
or Just make a ~/Downloads/rtt/rtt-code/wordpress/myWebpage directory and set up a git repo in it. http://www.whistlenet.com/git-for-wordpress/
I think you just need to go into the wordpress folder and then run the git status command. As the directory(rtt-code) is not a git directory but contains within it the git repo, that is wordpress, you are getting this error.
Inside the wordpress folder, all your git commands would work perfectly well...

How to clone WordPress theme from github

I've been developing a wordpress theme on a dev site, and all along I've been pushing it to github. It's now ready to be deployed to my live site, but I'm not sure how to do that.
What I've tried so far (that didn't work) is creating an empty /wp-content/themes/my-theme/ directory on my live site, and I cd into it. Then I use git clone git#github.com:path/to/my-theme.git but that creates another directory inside of my my-theme/ directory with all of the theme files inside of it. To clarify, that now creates:
/wp-content/themes/my-theme/my-theme/[all theme files here]
But I just want the files from the github repo to be placed directly into the original empty my-theme directory that I created.
try git clone <repo> . -- you can specify the directory as the last argument.

Keeping WordPress in version control - separate repo for theme

I have my WordPress project under Git and have WordPress as a submodule. I want to keep my theme development in a separate submodule, but within the current setup and am having some difficulties getting the theme setup as a submodule.
Here is my file system:
/.git (master repo)
/index.php
/wp-config.php
/wordpress (WordPress repo as a submodule)
/wp-content
themes
test-theme (theme repo)
.git
index.php
(etc...)
Now when I push my master repo to github, and try and clone it on another machine, the wordpress submodule downloads fine, but my theme folder does not, and I get an error about submodule not being defined.
I've tried using this to add my theme as a sub-module:
git submodule add ./wp-content/themes/test-theme/.git ./wp-content/themes/test-theme
but I get the following error: "remote (origin) does not have a url defined in .git/config"
How do I defined my theme repo as a submodule, when it is essentially hosted "inside" the project and not at a separate repository online?
Thanks.
I'm still relatively new to using submodules but I have been trying to do something similar and found two blog posts quite helpful: one by Clint Berry and another by David Winter.
The principle of a submodule is that it should have a separate repo and then when you add that submodule to a new project the add submodule command should be pointing to the repo:
git submodule add https://github.com/youruseraccount/test-theme.git ./wp-content/themes/test-theme
git init
git update
I believe this is why you are getting the error, there is no URL associated with the origin. Look in the files .gitmodule and .git/config to confirm. If I am correct, the git init will add the necessary entries in .git/config and git update this will pull the theme from the repo and put it into the subdirectory.
See here for how to commit changes to the submodule and here for how to remove the submodule.

Resources