2

I'm using Github with my Wordpress website.

Currently it tracks the parent Wordpress folder, which essentially tracks everything.

enter image description here

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?

James Mitchell
  • 2,387
  • 4
  • 29
  • 59
  • Do you want to replace your current repository contents with the theme? Or create a new repository and add the theme in there? – yarwest Jan 01 '18 at 18:21
  • 1
    Possible duplicate of [Detach (move) subdirectory into separate Git repository](https://stackoverflow.com/questions/359424/detach-move-subdirectory-into-separate-git-repository) – phd Jan 01 '18 at 18:37
  • Have you get the answer which helps you solve the problem? If yes, you can mark the answer. And it will also benefit others who have similar questions. – Marina Liu Jan 11 '18 at 08:39
  • Related: https://stackoverflow.com/questions/11559266/keeping-wordpress-in-version-control-separate-repo-for-theme – Jesse Nickles Mar 02 '22 at 15:42

2 Answers2

0

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)

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
0

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

Marina Liu
  • 36,876
  • 5
  • 61
  • 74