0

Consider that you a have git repository with subfolders:

  • firstFolder
  • secondFolder
  • thirdFolder
  • ...

and the repository has multiple branches:

  • firstBranch
  • secondBranch
  • thirdBranch
  • ...

And you want to turn, for example, the firstFolder and its clones/mirrors across different branches into an independent repository. This is the equivalent of git checkout to every one of those branches and git rm -r the other folders and then git mv the content of that specific folder to the main folder. But I was wondering if there is a more canonical way to do this? One solution would be writing a script to list all the branches and repeat these steps across those; I thought maybe there is a git solution to this.

Foad S. Farimani
  • 12,396
  • 15
  • 78
  • 193
  • 1
    Does this answer your question? [git move directory to another repository while keeping the history](https://stackoverflow.com/questions/41811986/git-move-directory-to-another-repository-while-keeping-the-history) – Brian61354270 Mar 17 '20 at 22:21
  • @Brian It is close, but is not exactly what I need. I don;t want to move a folder to another repository. I just want to turn one subfolder to its own. – Foad S. Farimani Mar 17 '20 at 22:29
  • 1
    Foad, the process is the same for moving a directory to an empty repository as for moving a directory to an existing repository. Simply checkout the repository, filter-branch to extract the desired directory as described. The only difference between your case and the one describe in the linked question is that you may skip the final cherry-pick step to merge the single-directory repository with the target repository. – Brian61354270 Mar 17 '20 at 22:31
  • @Brian Thanks. I will try to understand the solutions on that page and then come bakc here if I had more questions. – Foad S. Farimani Mar 17 '20 at 23:14

0 Answers0