book-git-commands/src/example/create-new-repo-from-subdir...

17 lines
505 B
Markdown

# Example: Create a new repo from a subdirectory
Useful if you want to pull a directory, and its commit history, out into a new repo.
```bash
# Clone the repository into a new directory.
git clone _.git
# Get only the files and commits impacting a particular directory.
git filter-branch --prune-empty --subdirectory-filter <pathToDirectory> <branchName>
# View and then update your remotes with the new repo location.
git remove -v
git remote set-url origin _.git
git push -u origin <branchName>
```