Skip to content

Instantly share code, notes, and snippets.

  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save Poxios/3f46a896e789ac7ed5318755a543d40c to your computer and use it in GitHub Desktop.
Git: move files in an subfolder keeping history

Change structure of project folder with Git

I have this structure:


I want this structure:


The benefits

  • Keep away from the Internet my .git folder
  • Wordpress files separated in a sub-folder
  • Keep Git history changes
  • Hide from the Internet deployment scripts or project sensitive informations

Move files with git and keep file history

  1. Be sure you don't have files uncommitted, if not commit them before next step.

    git status

  2. In project-directory create public subfolder

    mkdir public

  3. Move files with git mv except public subfolder to avoid errors

    for file in $(ls | grep -v 'public'); do git mv $file public; done;

  4. Move specific files like .htaccess etc...

    git mv .htaccess public/

  5. Commit changes

    git commit -m 'Moved files to public/'

  6. That's all !

    git log -M summary

To see file history of moved files

In Bash:

git log --follow

In SourceTree:

On logging file(s) you have to check [x] Follow renamed files

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment