Home > Software engineering >  Git - Multiple individual repositories inside one parent repository
Git - Multiple individual repositories inside one parent repository

Time:01-17

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.

CodePudding user response:

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) }'

CodePudding user response:

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

  •  Tags:  
  • Related