Search code examples
gitgithubrepositorygit-submodulesgit-subtree

Git change the repo path of a subfolder


I've got a git structure like the following:

/web_app
-- /static
-- /templates
-- app.py

Having this, when i push to my repo, its pushed following exactly that folder structure, but what I want in the repo is this structure:

/web_app
--  /web
    -- /static
    -- /template
-- app.py

So what I want to do is somehow, from my folder in my pc push the folders /static and /templates into /web/ in repo, and when pulling or clonning, keep the original folder structure.

I've been searching trough docs for submodules and subtrees but either I didn't understand well how they work or they don't satisfy my necessities.

So, Is there any way to accomplish this?

Thanks in advance!


Solution

  • My first recommendation is to download the git cheat sheet and keep it handy on your desktop.

    The command to accomplish what you want to do is git mv <source> <destination>. in the shell. The documentation for the command states that it will work on directories.

    In your case, this means, from the /web_app directory, you should make your "web" directory:

    md web
    

    Then you should move your directories

    git mv ./static ./web/static
    git mv ./template ./web/template