Setting up git on wordpress: Issue with git add - wordpress

I have been trying to setup git on a WordPress site, The issue seems to be that while I run git add --all.
The files get deleted for some reason. Not sure what seems to be the issue.

Related

Update Wordpress when using Github Wordpress skeleton

This is mainly a clarification about dealing with public Repos for git beginners.
I have a local git repo with a clone of Wordpress skeleton (https://github.com/markjaquith/WordPress-Skeleton). This includes Wordpress as a submodule (https://github.com/WordPress/WordPress).
If I update Wordpress from the dashboard it will require me to update my git repo.
There is a note about making a pull request if the repo falls behind but I am working on my localhost so can't do that.
If I had a hosted repo, should I send a pull request to the WP skeleton or WP repo?
I have a fresh install at the moment but if I were to customise it I probably wont want to (or Shouldn't) push so what would I do in this case?
Note: This is using the Wordpress repo as an example but I am curious about the best/general practice.
I'm having some similar questions, mainly about what the best practice is when updating Wordpress. Should I use the Dashboard once on remote, or should I continue to update the Wordpress Submodule in WP-Skeleton.
I can tell you this, you can update Wordpress via the Submodule in WP-Skeleton by using the "Git Checkout" command on the submodule and choosing the latest release number (4.1 as of this writing). Its extremely simple in SourceTree if you're new to Git and need an interface to help.
This is a little late but I asked the author of the repo and he answered me in his QA repo on Github.
This is the answer Mark Jaquith gave there which worked:
For your personal sites, which have likely wildly diverged, the update
process is as follows:
cd wp
git fetch
git fetch --tags
git checkout 3.9.1
cd ../
git add wp
git commit -m 'Update to WordPress 3.9.1'
git push origin master
Let me break that down:
cd wp — move into the WordPress submodule directory.
git fetch — Pull down the latest changes from tracked branches.
git fetch --tags — Pull down the new tags. You do steps 2 and 3 in this order because otherwise you might have a tag that points to a commit that you don't yet have in your repo.
git checkout 3.9.1 — Checkout the 3.9.1 tag.
cd ../ — Move back into the main directory. At this point, the wp subdirectory will show as having changes, since it points to a different commit.
git add wp — Tell your main repo to stage the WordPress submodule repointing.
git commit -m 'Update to WordPress 3.9.1' — Commit that change git push origin master — Push your master branch (change if using a different branch) up to your origin remote (change if using a different remote).
You probably noticed that there
is only one variable here — the version number. So You could wrap that
up into a bash script that you check into your root directory. And
then you could just do something like: ./wpupdate 3.9.1. Or you could
write a script that iterates through a bunch of WordPress site
checkouts and does this process on each of them (I've done exactly
that).
I will also add that from the wp folder you can enter git tag to see a list of tags, this way you can make sure you get the latest one.

WordPress as git submodule, accidentally updated through WP admin instead of git, now modified content

I followed David Winter's workflow to "Install and Manage WordPress with Git." WordPress is a git submodule. On the latest WordPress 3.9 upgrade, I accidentally updated through the WordPress admin instead of via git. Now when I run git status I get:
modified: wordpress (modified content, untracked content)
Which makes sense. But I can't commit the modified wordpress content. The WordPress submodule is dirty. If I run git diff within my main repo, I get this:
-Subproject commit 22bb60277036651db73dc872eaa7d2a50276b00d
+Subproject commit 22bb60277036651db73dc872eaa7d2a50276b00d-dirty
What's the best way to fix this? If I run the following within my main repo, will it mess up my WordPress install? (Note: I had also updated some plugins.)
git clean -dfx # delete everything in the worktree that isn't tracked
git reset --hard # wipe all modifications to tracked files
git checkout 3.8.1 # return to previous version tag
Update: The commands above work perfectly. I checked the documentation on git clean to learn what the options 'd', 'f', and 'x' were: https://www.kernel.org/pub/software/scm/git/docs/git-clean.html. After I ran the previous commands within the WordPress directory, I was able to then checkout version 3.9, thus correctly updating WordPress.
The following commands worked perfectly:
git clean -dfx # delete everything in the worktree that isn't tracked
git reset --hard # wipe all modifications to tracked files
git checkout 3.8.1 # return to previous version tag
I checked the documentation on git clean to learn what the options 'd', 'f', and 'x' were: https://www.kernel.org/pub/software/scm/git/docs/git-clean.html. After I ran the previous commands within the WordPress directory, I was able to then checkout version 3.9, thus correctly updating WordPress.

Git checkout for submodules not working for WordPress

I have WordPress as a git submodule and it is checked out at tag 3.8.1.
I want to get the latest version of WordPress which is 3.8.2.
I have done the following structure:
/html
/wp - submodule to WordPress
I then run the following commands:
$ cd wp
$ git checkout 3.8.2
Previous HEAD position was 22bb602... Tag 3.8.1
HEAD is now at 5577e02... Tag 3.8.2
However when I go and check the WordPress dashboard it still tells me that I still need to update to 3.8.2.
3.8.2 is actually a tag, not a branch. It points to a specific commit. Pulling makes no sense there.
If you want to stay up-to-date with the 3.8 version use the branch 3.8-branch.
$ git checkout 3.8-branch
$ git pull
This was a complete red herring. The git checkout 3.8.2 was working. But I hadn't properly checked the file changes and there's no such indication that the files have been updated as when you do a git pull.
However the WordPress dashboard was thinking that I was not on the latest version because I am using a dutch translated version of WordPress.
So in the wp-config.php I have define( 'WPLANG', 'nl_NL' );
This then requires that you are using the nl-NL installation of WordPress from e.g. https://downloads.wordpress.org/release/nl_NL/wordpress-3.8.2.zip
However because I am using the github version of WordPress, that only has the US English version of WordPress. Its a hack, but to fix the problem I just edited the wp-includes/version.php file, to include the following line at the bottom, which is the only file that differs in the WordPress core for the translated version:
$wp_local_package = 'nl_NL';
Then WordPress is happy that you have the latest version.
Then you have to pull in the translation files.

How do I git out of this mess with a git submodule?

I've got a git repo with Wordpress as a submodule. I was trying to update Wordpress and really screwed things up. I just want to get all of the code from the 3.7.1 tag in the remote repository, but this doesn't work;
git fetch --tags
git checkout 3.7.1
Leaves a bunch of either "untracked files" or "uncommitted changes". I don't know what I'm doing wrong. I've tried so many things to get this submodule onto the 3.7.1 tag and nothing seems to work. If anything, I feel like I'm just making the problem worse. It shouldn't be that hard to just reset the code from the tag I want and discard everything else. Any help?
Here's the git nuclear option:
git clean -dfx # delete everything in the worktree that isn't tracked
git reset --hard # wipe all modifications to tracked files
git checkout 3.7.1
which looks appropriate here.

How to Upgrade and Deploy WordPress Install as a Git Submodule?

I am using a WordPress directory struture similar to Mark Jaquith's WordPress Skeleton, which has WordPress in a separate directory from the content as a submodule:
/content
/wp
/local-config.php
/wp-config.php
/index.php
I also use git and post-receive hooks to push my code changes up to my live server. It all works great except for when I try to upgrade WordPress and push that up to the live server.
This is how I setup the repo on my local machine and the remote server:
Local Machine
cd /www
git init .
git submodule add git://github.com/WordPress/WordPress.git wp
git commit -m "Add Wordpress submodule."
cd wp
git checkout 3.5
After checking out the tag, I get a warning from git about being in a 'detached HEAD' state. Since I don't plan on making any commits to WordPress, I don't think that should be an issue.
cd ..
git commit -am "Checkout Wordpress 3.5"
Remote Server
git init --bare
cat > hooks/post-receive
#!/bin/sh
GIT_WORK_TREE=/home/public git checkout -f
chmod +x hooks/post-receive
git remote add web ssh://user#server/home/private/code/wordpress.git
git push web +master:refs/heads/master
I get this error:
No refs in common and none specified; doing nothing.
Perhaps you should specify a branch such as 'master'.
fatal: The remote end hung up unexpectedly
error: failed to push some refs to 'ssh://userserver/home/private/code/wordpress.git'
After some googling, it looks like I can use this command to sync up the master branch up to the server (I have no idea how this works)
git push web +master:refs/heads/master
This doesn't help me though because I don't want to track master, I want to track a release tag, 3.5. Some more googling got me to this command:
git push web +3.5~0:refs/heads/master
To upgrade the submodule, I do this:
cd wp
git fetch && git fetch --tags
git checkout 3.5.1
git push web +3.5.1~0:refs/heads/master
Am I doing this correctly? All the tutorials I see for this just have git push web and they're done. Most don't even cover upgrading the submodule. This does work but I don't feel comfortable using this weird push syntax if I don't have to.
How do I push this detached HEAD state up to the server correctly?
I've also tried this using a branch with git checkout -b mywp 3.5 but when it comes time to upgrade, I don't know how to bring in the new 3.5.1 tag into my mywp branch.
Asked this on WP Answers, but it might be more appropriate here.
On the remote server try:
git submodule update --init --recursive
This will update all your submodules recursively
You can also issue:
git fetch --tags
This will update your local tags fetching updated list from the central remote repo.

Resources