Skip to content

Instantly share code, notes, and snippets.

@alces
Created October 28, 2015 15:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alces/4d425336757771875e53 to your computer and use it in GitHub Desktop.
Save alces/4d425336757771875e53 to your computer and use it in GitHub Desktop.
How to leave only one sub-directory in a git repository

The following command leaves only content of my/sub/dir in a master branch:

git filter-branch --subdirectory-filter my/sub/dir --prune-empty master

as a side effect, my/sub/dir becomes a root directory of a repository.

Full documentation on git filter-branch command could be found here: https://git-scm.com/docs/git-filter-branch

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