Avatar of userTester
userTester
Flag for United States of America asked on

Github repository sub folders

I have a single github repository which has sub folders. I want to have each sub folder be a separate repository. How do I make each sub folder it's own repository, totally separate from the current single repository, without having to push from my local repository?

Current github structure:

CSS (Repository)

1. Project 1 (sub folder)

2. Project 2 (sub folder)

3. Project 3 (sub folder)


I would like to make each sub folder it's own repository:

Project 1  (Repository)
Project 2  (Repository)
Project 3  (Repository)
Version ControlGitWeb DevelopmentProgramming

Avatar of undefined
Last Comment
Rob

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Pavel Celba

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
SOLUTION
pepr

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Pavel Celba

Update: Push operation is necessary but what's wrong with it?
userTester

ASKER
pepr,

I find the concept of sub modules interesting, so thanks for letting me know about them, but, even though it is a direct answer to my question as I presented it, my real problem, which I might not have described fully, has to do with removing the sub folders completely from its current repository, and creating separate new repositories for them.

Sub modules seem to solve the problem where the sub folders remain within the original repository, but are extended as new repositories outside of the original repository. I am not sure whether my understanding is correct though??
userTester

ASKER
pcelba,

The link you provided is very useful, so thanks for that.

The problem with pushing from local is being able to find each and every local project that was pushed to github, especially those that were done a while back, and of course, if there were just a few, that would not be an issue.

Github does allow the moving of a child file to it's parent's location making it a sibling of the parent, but it doesn't seem to allow the file to be moved outside of the current repository, into a new repository. This is what I would like to confirm though.

pepr highlighted the concept of sub modules, which hints that there might still be an option that excludes pushing from local.

Surely, it should be a simple thing to copy files from one repository to a new repository within the same github profile, without needing to push from local?
Your help has saved me hundreds of hours of internet surfing.
fblack61
pepr

(A bit dormant thread :)

my real problem, which I might not have described fully, has to do with removing the sub folders completely from its current repository, and creating separate new repositories for them.

Here the pcelba's advice should be used. Think about how would you separate the subdirectories without having Git. To save the history, you would copy the entire project somewhere (to have the old status). Then you would move the subdirectories elsewhere, which can also be interpreted as copy them somewhere else and delete them in the original location. However, you do not have "move" in Git in the sense it would change the history. This way, you have to clone the original, and then you have to remove from the clone all that you do not need. But you want to do that not only in your working copy, but also in the repository itself. This is where the filter-branch helps.

See also https://git-scm.com/book/en/v2/Git-Tools-Rewriting-History#The-Nuclear-Option:-filter-branch
userTester

ASKER
pepr,

Is this what you mean:

1.

clone CSS repository to local

2.

git mv each project to it's own separate new git repository

3.

git rm cloned local CSS repository

4.

on Github, make a new repository for each project

5.

git commit and push each local project to it's own Github repository
I will have to study the filter-branch technique a bit more, but I think it can be quite useful in this scenario.
pepr

Well, not exactly. The git mv, and git rm are only helper commands that can be replaced by "usual" OS commands combined with capturing changes (see https://git-scm.com/book/en/v2/Git-Basics-Recording-Changes-to-the-Repository#Moving-Files). However, it only changes the status of the last snapshot. The repository after that still stores all the history, including the history of the removed subdirectories. So, after being happy with the "cleaned" structure, you may want to completely "prune" everything that is unrelated to the current status. This means, you erase the history that you do not want. If you extract only one subdirectory from a huge project this way, it is likely that your repository becomes much smaller (which may be the main goal). Or you may want to remove "the secret parts of the bigger project" (say your love letters that came inside by accident). You can prune it so that there is no trace in the modified history, and there is no chance to extract the secrets from the repository (it is simply not inside any more). Only after pruning the smaller repositories, you may want to publish it to GitHub as separate projects.
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Rob

I've requested that this question be deleted for the following reason:

Not enough information to confirm an answer.