Skip to content

Instantly share code, notes, and snippets.

@beck
Created April 26, 2019 19:00
Show Gist options
  • Save beck/e7b9d25389c953dbefb4bf712c52c247 to your computer and use it in GitHub Desktop.
Save beck/e7b9d25389c953dbefb4bf712c52c247 to your computer and use it in GitHub Desktop.
git filter folder
#!/bin/bash
set -eux
# Use this script to prune away everything but `foo/bar/somedir`, resulting with only `somedir`
# in the root. Using `--subdirectory-filter` is undesireable because it hoists all the contents
# of `somedir` into the root.
mkdir -p __github-migrate__
mvplz="if [ -d $1 ]; then mv $1 __github-migrate__/; fi;"
git filter-branch -f --tree-filter "$mvplz" HEAD
git filter-branch -f --subdirectory-filter __github-migrate__
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment