1

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.

Noah
  • 4,601
  • 9
  • 39
  • 52
  • Wordpress isn't very good for git use because of the folder structure - the core code is in the root and the stuff you can edit (`wp-content`) is a subfolder. With git you can use a submodule, but in this case your base repo would have to be Wordpress itself and your submodules would have to be your plugins/themes, which is hardly ideal in terms of maintenance. – jraede May 02 '14 at 18:40
  • @jraede I don't understand why. I just want the theme folder as the project. I'll clone it in it's right place within Wordpress installations. What difference do the other files make? – Noah May 02 '14 at 18:51
  • Oh, sorry I misinterpreted what you were asking. You're going to want to make your theme folder its own git repo, remove it from your project, and then re-add it as a submodule. http://stackoverflow.com/questions/1871282/nested-git-repositories – jraede May 02 '14 at 18:54
  • But why keep the Wordpress files in a repo at all? They are not being edited. Seems like it would make deployment a bit more complicated. – Noah May 02 '14 at 18:59
  • This question may be a better fit for [wordpress.se], not sure `:/` –  May 04 '14 at 15:49
  • Definitely not exclusively a Wordpress issue. More to do with git. – Noah May 04 '14 at 17:15

1 Answers1

1

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
Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • This seemed to work but somehow the files came back. The files from /wordpress/themes/mytheme are now in /wordpress, but so are all the other files originally there. I don't know how this happened because I don't remembering pulling or cloning. – Noah May 05 '14 at 17:35
  • 1
    @Noah they should be re-generated by a process which isn't related to Git, but related to WordPress management. – VonC May 05 '14 at 17:36
  • I don't see how. If there is not wordpress there, how can it manage itself? – Noah May 05 '14 at 17:38
  • 1
    @Noah if you clone that repo again, would those files be part of the clone? – VonC May 05 '14 at 17:41
  • Looking at my commits with Gitlist, it doesn't show me adding those files back. Cloning just gets the theme files as intended. Maybe this is related to Dropbox? – Noah May 05 '14 at 17:46
  • 1
    @Noah maybe: using Git with Dropbox is generally *not* a good idea. (as in, for instance, http://stackoverflow.com/a/2129286/6309) – VonC May 05 '14 at 17:48
  • I've used Time Machine to revert the changes. They happened between 1AM last night and now. I'll Dropbox-proof my dev folder now. Thanks, VonC. – Noah May 05 '14 at 17:54