L
L
Leonid2022-01-16 12:08:09
git
Leonid, 2022-01-16 12:08:09

How to add a folder higher in the directory to the git repository?

There is a WordPress site whose contents of the child-theme folder are in the github repository.
You need to include the folder of the dependent plugin in this repository (we don’t want to create a separate repository for the plugin!)

- public_html
-- wp-content
--- themes
---- child-theme
----- .git
--- plugins
---- my_plugin


I understand correctly that you will need to do the following:
- move the .git folder from the child-theme folder to the public_html root folder
- add all exceptions to .gitignore except for the child-theme folder and the my_plugin folder

- public_html
-- wp-content
--- themes
---- child-theme
--- plugins
---- my_plugin
-- .git
-- .gitignore

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Kuznetsov, 2022-01-16
@easycode

In general, you think correctly and the recipe will work. After moving the repository, git will say that you have moved all the theme files to a subfolder and will have to create a commit with this operation. But although you will see the old commit history, it will be difficult to use it, since the paths have changed.
It would be more correct to use the filter-repo command before moving the .git folder to rebuild all previous commits as if the repository was originally in the root.
Initial folder structure

public_html
└── wp-content
    β”œβ”€β”€ plugins
    β”‚Β Β  └── my_plugin
    └── themes
        └── child-theme
            └── .git

Prepare the old repository for migration
git filter-repo --to-subdirectory-filter wp-content/themes/child-theme

We get such a structure
public_html
└── wp-content
    β”œβ”€β”€ plugins
    β”‚Β Β  └── my_plugin
    └── themes
        └── child-theme
            β”œβ”€β”€ .git
            └── wp-content
                └── themes
                    └── child-theme

Then we move the .git folder and everything else in the child-theme folder to the root of the site.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question