how to install roots theme and wordpress as git submodule - wordpress

I am wordpress developer and want to use git in wordpress. I also want version control in my wordpress so that everything in the projects gets updated frequently.and also how to install wordpress as git submodule?
thanks,
suku

Just add wordpress as a submodule from the root directory of your project like this:
git submodule add git://github.com/WordPress/WordPress.git ./your/submodule/directory
Make sure that the directory doesn't exists before executing the above command.
I like to keep my root project directory nice and clean, and I use Wordpress Skeleton in a directory called "app," while Wordpress sits in a directory called "wp," therefore I execute the command below from the root project directory.
git submodule add git://github.com/WordPress/WordPress.git ./app/wp/
This makes it really easy to update wordpress and keep everything under version control. To update to 3.8.1 do the following:
cd wp
git fetch && git fetch --tags
git checkout 3.8.1
cd ./
git add wp
git commit -m “Updated to WP 3.8.1”
git push
I wrote an unfinished article about it over here: http://www.kj-prince.com/wordpress-development-deployment/
Hope this helps.

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.

Create local git repository based on local repository based on github repository and keep it updated

I have some basic git knowledge but I'm not sure how to accomplish this.
I am trying to clone (?) github WordPress starter theme underscores. The idea is to create a basic framework based (with some modifications) on that repository. Then create other themes with that framework as the base.
So it should look something like:
copy github underscores repository to local
create a local repository my_framework from the underscores one, modifying certain parts of those files always (such as the name) and adding some other files
create new local repositories my_theme1, my_theme2 based on my_framework
The goal is to keep everything updated with any underscores update, while changing and modifying the framework and the themes. Once the content from github is pulled it should keep (or inform) of any updates, but I don't need any change I make locally to go back in the path.
I am not sure which path to follow, and would appreciate any help or pointer.
The goal is to keep everything updated with any underscores update, while changing and modifying the framework and the themes
That is called the triangular workflow:
fork (see "Fork a Repo") the repo automattic/_s
clone that fork locally,
git clone /url/my/fork myfork
add as remote upstream the original repo
cd myfork
git remote add upstream https://github.com/automattic/_s
From there, with git 2.9 or more, configure:
git config --global pull.rebase true
git config --global rebase.autoStash true
Finally, each time you want to update your branches (where you modify your own version of the original repo), do a
git checkout mybranch
git fetch upstream
git rebase upstream/master
Then you can merge that updated branch (after testing it) to your other repos my_theme1, my_theme2, cloned from myfork.
cd my_theme1
git fetch
git merge origin/mybranch
If you want to work locally only, you can skip the fork step and clone directly the original repo.
you should learn about child themes. the concept of it is having a main theme - which gets updated - and a child theme that'll you'll modify, add content, create different templates & styles... everything to your needs.
I'd recommend taking some minutes to read this throughtfully: https://codex.wordpress.org/Child_Themes
Assuming you using a terminal,
cd to the themes directory:
cd [PROJECT]/wp-content/themes
Now clone _s to your project:
git clone git#github.com:Automattic/_s.git [THENE-NAME]
After the clone ends you can start working with your new theme.
cd to theme directory:
cd [THENE-NAME]
and create another remote for your repo.
git remote add [NEW-RENOTE-NAME] [NEW-RENOTE-URL]
From now on, you can push change into your private remote:
git push [NEW-RENOTE-NAME] master
and if you want to get updates from _s repo you can just:
git pull origin master
Good Luck!
you could do something like
git clone https://github.com/Automattic/_s.git
create directory my_framework with mkdir my_framework(if on windows)
cd my_framework
git init
git remote add <_s> <PATH to your local underscore>
git pull(to get latest version of underscore)
again:
mkdir my_theme1
cd my_theme1
git init
git remote add <my_framework> <PATH to your local my_framework>
git pull
Hope this is what you are looking for!
What you want to do is called nested git repo. GitHub does not allow nested repositories. You can use GitSubmodule or subtree. It is done for when projects become bigger.
One copy of underscores will remain as "control".
Second copy of underscores will remain is starting of my_framework. Third copy is copied and modification of my_framework.
You can :
Update underscores repo aka WordPress starter theme underscore master separately
Change in your framework separately
Send pull request for wherever you want to contribute
my_theme1, my_theme2 are not versions but separate softwares. my_theme1 as example can have nth versions. Here are sample steps :
cd ~
mkdir parentrepo
cd parentrepo/
git init .
mkdir child1
mkdir child2
cd child1/
git init .
echo "FirstChildRepo content" > child1repofile.txt
git add .
git commit -a -m "Adding FirstChildRepo content"
cd ../child2/
echo "SecondChildRepo content" > child2file.txt
cd ..
echo "parentrepofile" > parentFile.txt
git add .
git commit -a -m "Adding Parent Repo content"
# verify whether working independently
cd ~/parentrepo/
git log
cd ~/parentrepo/Child1Repo/
git log
# try cloning parent, verify the contents
cd ~
git clone parentrepo/
cd parentrepo/
ls -a
./ ../ .git/ child1/ child2/ parentfile.txt
cd child1/
ls -a
./ ../
Work after this step to clone, update in the way whatever like others written.
You can "auto update" too. Add files named post-checkout & post-merge to .git/hooks directory of the needed repositories and add this into each of them:
#!/bin/sh
git submodule update --init --recursive

WordPress plugin isn't deployed to OpenShift

After setting up WordPress site on OpenShift, I tried to upload new plugin from my local repo, according this manual, but nothing was uploaded to OpenShift.
Step I've done:
# cloning WordPress app from OpenShift
rhc git-clone -a wpdev
# Going to plugins folder on local machine
cd ~/openshift/wpdev/.openshift/plugins
# cloning my plugin from GitHub to openshift plugins folder
git clone https://github.com/samuelsh/youtube-channel-player.git
# standart add/commit/push
git add plugins
git commit -m "youtube-channel-player deploy to openshift"
git push
After checking my wpdev app on openshift, looks like my plugin isn't uploaded.
What could go wrong here?
Thanks
Well, appeared it was git submodule issues.
Trying explicitly add new files to repo resulted following error:
git add .openshift/plugins/youtube-channel-player/*
fatal: Pathspec '.openshift/plugins/youtube-channel-player/admin' is in submodule '.openshift/plugins/youtube-channel-player'
Removing the directory from git and adding it again worked for me:
git rm --cached directory
git add directory

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