How to do it...

  1. First, we'll decide which folders and files to keep in the new repository; we'll delete everything from the repository except those files. We'll store the files and folders to be kept in a string separated by | so that we can feed it to grep as a regular expression, as shown in the following command:
keep="org.eclipse.jgit.http|LICENSE|.gitignore|README.md|.gitattributes" 
  1. Now we are ready to start the conversion of the repository. We'll use the git filter-branch command, which can rewrite the entire history of the repository; just what we need for this task.
Always remember to make sure you have a backup of the repository you are about to run git filter-branch on, in case something goes wrong.
  1. We'll use the --index-filter ...

Get Git Version Control Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.