Skip to content

Instantly share code, notes, and snippets.

@qcom
qcom / git-filter-branch-move-files.md
Created Jun 8, 2020 — forked from fabiomaggio/git-filter-branch-move-files.md
Use git filter-branch to move all projects files to a subdir and rewrite all commits
View git-filter-branch-move-files.md
  1. Clone project

  2. Checkout all branches that contain the files that should be moved

  3. Delete the remote

  4. Run the filter-branch command:

    git filter-branch --tree-filter 'mkdir -p /path/to/tmp; mv * /path/to/tmp; mkdir subdir; mv /path/to/tmp/* subdir/' --tag-name-filter cat --prune-empty -- --all
    • All files are first copied to a temporary dir and move from there to the new destination
    • Existing tags are updated