0

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 Content of Folder_A -B Content of Folder_B 

The reason for this is an import from a TFVC repository to a GIT repository.

2 Answers 2

1

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 ... 

enter image description here

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> 

enter image description here

Sign up to request clarification or add additional context in comments.

3 Comments

Not suitable IMO — git subtree split changes the root folder. That is, instead of /FolderA the branch will contain the content of /FolderA at the root.
And once you extract the content you can use it as a branch, the question was to extract subfolders to a branch
It works great, but if I push everything, the commit history is gone :/ Is there any solution for it?
1

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

3 Comments

git mv Folder_A/* . Gonna remove it? The OP showed the folder is required.
Oh, you are right. I read it like that would be the new root for those 2 branches. Let me adjust that. Thanks, @phd
The requirements changed and we ended up using the git subtree split. But your way is great as well

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.