Templates and branches

When you use a repository as a template, does it pull all branches or just the master?

Before starting to use Classroom this year I was already using git to keep assignments. What I typically would do is create a student version in the master and then create a solution branch with a working solution. That way they were easy to keep together. I’d zip up the master branch, out of source control, and give that to students as a starter.

But now that I’m using Classroom and having the students create a repo from a template, I’m thinking it would be perfect if when they copied the template only the master came with it or, even better, there was a way to specify what branch they got.

Only the master branch of a template repository is passed on to students. Thus you’re good to go with your approach. Anyway, to keep the solution branch “secret”, remember to make the template repository private.

Just tried it and they get both branches. The solution branch doesn’t show up in the drop down list. But it does show that there are two branches, and the student was able to click through and view the code in the solution branch.

I’ve just tried it again and it worked as expected.

For my test, I started from a template repository containing master and gh-pages branches and when I proceeded further I got into the final repository only master, no gh-pages. I did this by using the mechanism creation from template, not really from within the Classroom dashboard but spawning the assignment into my account. As of now, I don’t have a Classroom ready to test in.

However, the Classroom relies on the exact same mechanism, so make sure to follow these instructions.

Hi @THSCS

I had the chance to test the mechanism from within the Classroom dashboard and it’s true that both the branches (master and gh-pages) got spawned into the student’s repo.

Then, my assumption that the behavior would have been the same as creating a new repo from a template on my profile was not correct.

This difference looks quite weird though.

As others have noted, all the branches come through when students create a repo through the GitHub Classroom mechanism, whether templates are involved or not. However, there’s a much bigger GOTCHA hiding just below the surface when you choose the template repository option. If two branches have shared history, that history is lost!. Or rather the fact that it is shared is lost. It appears that each branch gets copied separately, so if both branches had the same file, they’ll now have two identical copies of that file, but git will no longer know that they are the same file. As you might imagine, this breaks pull requests badly.

Why, yes. Yes, I did just get bit by this behavior. How could you tell?

1 Like
© 2017 GitHub, Inc.
with by
GitHub Education