0

I have multiple courses folders with all the files and exercises. Each one is a separate repo like this:

- courses (main folder; not a repo yet) - course1 -.git -ex1 -ex2 -... - course2 -.git -ex1 -ex2 -... 

Problem is I don't want to push them to separate remotes, I would like to create a "courses" repo on GitHub and push all other repos, while keeping isolated history for each course, and still being able to clone an individual course or the main courses folder with all included.

What would be the best approach to achieve this? I tried it with git-submodules but as far as I know I would have to publish each repository anyway.

2 Answers 2

1

You can maintain separately-rooted branches, one per course; cloners can either take the default of all history or pick just the course they want with the --single-branch -b option.

Quickest conversion from your existing setup would be in-place, assuming you've got a single branch for each course presently makes it really simple:

cd courses; git init git config advice.addembeddedrepo false for course in course[1-9]*; do git add $course git fetch ./$course HEAD:refs/heads/$course done 

and now your courses repo has a branch for each course; also, a default checkout from a full clone will create an empty directory for each; anyone doing that can

git ls-files -s | awk '$1==160000 { system("git worktree add "$4) }' 
Sign up to request clarification or add additional context in comments.

3 Comments

After this setup is done, what are the next steps? How should I push to the remote properly?
Just push. They're still submodules, but the fetch incorporated them into the main repo, you don't need the helper to find their histories with this setup, they're all already here.
Best way forward is probably try to implement this and ask specific questions about anything it leads you into you can't find your way out of. Remember that git add of a repository('s work tree), rather than adding a blob's content and recording the blob's id as what should be checked out there, records that work tree's checked-out commit id as the content that should be checked out there. That's all a submodule is, a repo that has the needed recorded commits.
0

Avoid using submodules as much as possible, use Git's subtree

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.