You can turn a folder within a Git repository into a brand new repository.

If you create a new clone of the repository beforehand, you won't lose any of your Git history or changes when you split a folder into a separate repository.

  1. Open Terminal (for Mac and Linux users) or the command prompt (for Windows users).

  2. Change the current working directory to the location where you want the new backup clone to be made.

  3. Clone the repository that contains the subfolder.

    git clone https://hostname/YOUR-USERNAME/YOUR-REPOSITORY
    
  4. Change the current working directory to your original clone.

  5. Run git filter-branch with the name of the folder you want to turn into a separate repository.

    git filter-branch --prune-empty --subdirectory-filter \
     YOUR_FOLDER_NAME master
    # Filter the master branch to your directory and remove empty commits
    Rewrite 48dc599c80e20527ed902928085e7861e6b3cbe6 (89/89)
    Ref 'refs/heads/master' was rewritten
    
  6. The repository now contains all the files that were in your subfolder. Note that although all of your previous files have been removed, they still exist within the Git history. You can now push your new local repository to a new repository on GitHub Enterprise.

    git push origin .
    
  7. Rename the remote URL on your new backup clone to point to the new remote repository on GitHub Enterprise.