-2

When creating course programming assignments I often work in a Github repo. These repos usually contain commits that have the solution to the assignment. Since I don't want to make those commits available to the class is there a way to prohibit access to the commit history?

Right now I end up having to create a brand new repo and copying the code in manually so there's no commit history. Or providing a zip of the repo. But a zip is awkward because sometimes I want to make a change to the code in the assignment. There must be a better way! (I'd be psyched for solutions that can be done through the Github GUI if possible. But I'll settle for command line.)

Luke
  • 2,008
  • 1
  • 12
  • 13
  • 1
    for this requirement there is no out of the box solution in Git, I can advice you a git workflow that would work if you have paid version of github – Player_Neo Feb 15 '20 at 18:51
  • Well I have an educational account. I'm presuming it gives me the same options as the paid version (e.g. I can make repos private). If it's a simpler workflow than what is described in the answer below I'm interested. . . . – Luke Feb 15 '20 at 20:04

2 Answers2

1

I'm not sure if there is a way to restrict access to specific parts of the history. It's also probably not a great idea to delete the history because you may want to refer to it later.

If your students don't need access to any of the commit history, and you are just trying to avoid copy/pasting code into a new repo, then you can copy the existing repo into a new directory, and then delete the entire .git directory to blow away the history. Then just initialize a new repo with git init, commit the entire codebase, and follow the normal steps to create a remote repository and push to it.

You'll be left with a new repo to give your students that has no history but all the same code.

C-RAD
  • 511
  • 3
  • 11
  • Thanks for the feedback. This is how I'm doing it now. But it's cumbersome. A simple checkbox in Github settings labeled "Hide commit history" could solve this. For what I do (and I would think for what many other people do) it would be helpful if Github catered to it. – Luke Feb 15 '20 at 20:01
  • Ya that would be nice. Do you have a lot of repos to do this for? You could write a bash script to automate a lot of it not all of it. – C-RAD Feb 15 '20 at 20:48
  • Also if you are trying to keep the student's repos up to date with yours, you can use cherrypick to move commits across even if the new repo isn't a fork of the first. – C-RAD Feb 15 '20 at 21:35
0

Git alone doesn't offer your expectation out of the box. You can achieve this by a git workflow with any Git-repository manager Ex. GitHub and GitLab.

Step 1: You need to have one private branch. Consider master branch for this example, Which is accessible to only the users who has specific privilege for this branch.

To add such restriction on any branch please refer this post How to restrict access to master branch on git

Step 2: You need a public branch which is created from the specific commit (where you have committed only assignment not solution). This branch will not have any history from this commit. (means no assignment solutions)

to create a branch from a particular commit refer this post Branch from a previous commit using Git

By following above workflow you would no longer needed to provide a zip of the repo while avoiding the previous assignment solutions visible from history of the new repo.

Ask your developers to create a new branch from public the branch. Everyone will have their own space.

To create a new branch from the newly created public branch refer this post Create a branch in Git from another branch

Player_Neo
  • 980
  • 1
  • 9
  • 22
  • Hmmm... per your suggestion I created two branches on Github. But there doesn't seem to be a way to make only one of the branches private. And while I can set different rules for each branch I can't prohibit read access. So if what you describe above is possible it certainly doesn't seem like an easily implemented solution. At least not on Github. – Luke Feb 17 '20 at 08:37