Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save smoya/fd43c90c25fd2be78c4c to your computer and use it in GitHub Desktop.
Save smoya/fd43c90c25fd2be78c4c to your computer and use it in GitHub Desktop.
How to move files from one directory to another inside a git repository
git filter-branch --prune-empty --tree-filter '
if [[ ! -e foo/bar ]]; then
    mkdir -p foo/bar
    git ls-tree --name-only $GIT_COMMIT | xargs -I files mv files foo/bar
fi'

Where foo/bar is the new dir where your files will be placed.

Source: http://stackoverflow.com/a/4042965/1863234. Thanks to Dan Moulding.

@sp-juan-hernandez
Copy link

functional git!

@douglascamata
Copy link

There is also a Github help article that explains how to do the whole thing: https://help.github.com/articles/splitting-a-subfolder-out-into-a-new-repository/

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