Is it possible to turn subfolders of a GIT repository into its branches?
Going from one branch with folders
-main
/Folder_A
/Folder_B
readme.md
To many branches
-main
readme.md
-A
/Folder_A
-B
/Folder_B
The reason for this is an import from a TFVC repository to a GIT repository.
CodePudding user response:
Is it possible to turn subfolders of a GIT repository into its branches?
Of course, there is a simple command which will do it, it will convert the folder to a branch with all the history
git subtree split ...
Split the "main" into branches with git subtree split <path> -b <branch>
and then add you can push the branch to the remote.
# split the "main repo"
git subtree split -P path -b <branch1>
CodePudding user response:
Will the branches remain separate from now on? If they will remain separate, fell free to create two new branches from main, say A
and B
. Then, in main
, delete the 2 folders, and in each of the separate branches do the necessary adjustments... say, in A
git checkout A
git rm readme.md
git rm Folder_B
git commit -m "Removing unnecessary stuff from this project"
This should be good enough. This way you get to keep the history of the common development up to this point in all 3 branches. If you don't want that and you would rather have them separate from the beginning as separate projects, then you should consider using git filter-repo https://github.com/newren/git-filter-repo