情報科学屋さんを目指す人のメモ

方法・手順・解説を書き残すブログ。私と同じことを繰り返さずに済むように。

WordPressを丸ごとGitHubで管理する

Git (9) GitHub (3) WordPress (80)

WordPressの本体・テーマ・プラグインなどなどを、丸ごとGitHubに突っ込んで管理することにしました。その作業メモです。

GitHubにレポジトリを用意

ひとまず、GitHub上にレポジトリを用意しました。リモートレポジトリを用意する、という意味では何でも良いのですが、用途的に非公開にできたほうが良いと思います。

自分は有料会員なので、プライベートレポジトリを作成しましたが、そういう場合はBitbucketを使うと良いかと思います。

GitHubであれば、レポジトリ作成画面で、「Add .gitignore」の設定で「WordPress」を選択しておくと良いと思います(自分もそうしました)。README と license はとりあえず無しで(非公開だし)。

レポジトリを作ったら、アクセスするためのhttpsで始まるURLを取得しておきます(例:https://github.com/user-name/repository-name.git)。

ローカルレポジトリを作成

そうしたら、WordPressが動作しているサーバ上で、WordPressのルートディレクトリに移動します。wp-config.phpがあるディレクトリです。

そこで、まず「$ git init」を実行しました。これで、WordPress全体がレポジトリになります。

% git init
Initialized empty Git repository in /var/www/did2memo.net/wp/.git/

remoteの登録とpull

続いて、「$ git remote add origin https://did2@github.com/did2/did2memo-net-wp.git」を実行しました。

最後のパラメータは、先ほどのURLに「did2@」を差し込んだものになっています(理由と効果はこちら)。

そうしたら、「$ git pull origin master」を実行します。これで、.gitignoreが降ってきます。

.gitignoreを作り込む

.gitignore を編集するのに使える git add の dry run」を利用して、.gitignoreを作りました。

一度で完全なものを創る必要はありませんが、とりあえずこんな感じ:

~*
*.swp
*.log
.htaccess
sitemap.xml
sitemap.xml.gz
wp-config.php
wp-content/advanced-cache.php
wp-content/backup-db/
wp-content/backups/
wp-content/blogs.dir/
wp-content/cache/
wp-content/upgrade/
wp-content/uploads/
wp-content/wp-cache-config.php
wp-content/plugins/wordpress-popular-posts/cache/
wp-content/plugins/wp-file-cache/cache/
wp-content/plugins/did2-ab-testing/tmp/

メモ:

error: open("wp-content/plugins/wordpress-popular-posts/cache/timthumb_int_7c1481b35b5f9a95576b0855e96a7d0d.timthumb.txt"): Permission denied
error: unable to index file wp-content/plugins/wordpress-popular-posts/cache/timthumb_int_7c1481b35b5f9a95576b0855e96a7d0d.timthumb.txt
fatal: adding files failed

commit と push

後は「$ git add -A」でざっくり add して、「$ git commit」「$ git push origin master」で完了です。

自作プラグインのgitレポジトリがネストしていると思ったけれど

実は、この作業前は、自作WordPressプラグインのgitレポジトリをネストしてしまい、git submoduleだとかgit subtreeだとかのお世話になるかも、と思っていたのですが、途中で、githubにpushするときは、専用のディレクトリで作業していて、WordPress本体とは別管理だったことに気が付きました。

つまり、WordPressのディレクトリの中に.gitディレクトリは一つも存在しておらず、.gitignoreを作る以外は、かなりスムーズでした。

コメント(0)

新しいコメントを投稿