3

Does git support a concept of a sub branch; ie a branch of a branch

For example a group of teachers have a bare shared repo on a network drive (no server ssh authentication etc) that they pull and push to on a shared drive merging into master when appropriate.

This repo would include teacher files such as worked solutions as well as student files.

Students shouldn't clone this repo nor checkout their respective teachers branch directly as it contains the answers.

But the repo could contain a branch for each class/topic with only student files that tracks upstream changes. Students then branch this branch to do their work. Teacher tracks the student branch as a remote and pulls in the work.

The closest I have come to the above is cloning a single branch into a separate repo and having students branch in that repo. The problems with the above include obvious data duplication (windows support of system-links within git is poor) and extra class/topic repos that have to be kept updated with upstream changes.

Any ideas how to better support this workflow in Git/LibGit2 ?

ArchNemSyS
  • 367
  • 2
  • 4
  • 17

3 Answers3

4

There's no notion of a main branch in git (master is a completely normal branch that git provides by default). You can branch off of master, you can branch off of any other branch, you can branch off of a branch of a branch of a branch of a branch.

To your specific questions, git doesn't have a concept of branch visibility. If I clone your repo, I get all of the branches just fine, and it doesn't matter how your local repo tracks the remote branches.

In short, if you don't want people having information that's available to the repo, don't allow them to clone it. Provide a different remote repo with just the information you need, and push only the relevant information there.

So for example, my repo has branches public, private-1 and private-2, I can push all of my branches to origin (git push private-remote private-1 etc), and have another remote setup where you strictly only push public to it.

Your students then clone the public remote, branch off of public, push their changes and their own branches, then you can pull those branches from public-remote and push into your private-remote. Git supports multiple remotes just fine.

Madara's Ghost
  • 172,118
  • 50
  • 264
  • 308
  • Ideally, the students would push their changes to their own personal repos. I can see how a `public-remote` common to all students would get very messy after more than 5 students have pushed to it. It would also be too easy for a student to mess things up on purpose. If you are on a school network, you probably already have some kind of public folder per user, that's typically where you'd make the student publish their repo. The teacher can then `git fetch /pub/student_id/course_42 homework_1:student_id_hw_1`, which would be easy enough to script. You don't have to give write access. – Gauthier May 05 '15 at 11:38
  • @Gauthier In that case, a PR system works very nicely. All students fork the repo from the original, clone that, push there as they please, and then submit a pull request to the teacher, asking them to merge their changes. – Madara's Ghost May 05 '15 at 11:44
  • @MadaraUchiha Exactly, that's the workflow I would use, but not necessarily with an additional system to fork and send requests. I'd just tell the students how to name their branch (`homework_1`, for example), and to push it in their public clone at a specific accessible location (`/pub//`, for example) before the deadline. If they can't manage that, they'd probably not make good coders anyway :) – Gauthier May 05 '15 at 11:57
2

Does git support a concept of a sub branch; ie a branch of a branch

No, a branch can be renamed, deleted or rebased (ie moved around) at any time.

It does support the notion of "namespace" (or hierarchy, or group), with the name of the branch including one or several "/": class/topic can be the name of a branch.

You find a similar use of namespace with gitolite (an ACL to control access to Git repos based on authentication).
See:

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • gitolite looks to be a highly viable solution unfortunately in my particular case I have no port access nor server permissions to set-up any kind of server. I will test the suggested namespace method ITCRepo/TeacherBranch/StudentSubBranch/Class/Student – ArchNemSyS May 05 '15 at 11:18
  • @ArchNemSyS I only mention gitolite to illustrate the usage of branches with '/' in their name. It is to to suggest you should use an authorization layer. – VonC May 05 '15 at 11:19
1

I use a similar flow, but with two distinct histories (i.e. two different repositories that do not have any commit in common): one for teachers, and one for students. Having two separate histories has several advantages:

  • I can include generated files (e.g. *.pdf) in the student's repository, and track source files (e.g. *.tex) in the teacher's one.

  • I do not need to show individual commits made by teachers on the student's repository. They just see ~1 commit per class saying "new class online".

  • I chose which file I want to publish.

In my teacher's repository, I have a makefile with an make install target that copies the generated files to the student's repository. For convenience, I have targets make git-commit, make git-push that run git commit and git push in the student's checkout.

On the students side, they run git clone once, git pull whenever I add new stuff. The can use my repository as a skeleton for their lab works, and work collaboratively (I advise them to use one remote for their coworker and one remote for me).

Matthieu Moy
  • 15,151
  • 5
  • 38
  • 65
  • This best represents the desired work-flow, but I will combine the above name-spacing where different groups of students study the same topic like advanced computing that extends core computing. – ArchNemSyS May 05 '15 at 15:20