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.


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?


Hey I’m new to github classroom and I wanted to know what everyone was doing about this? I found issues on the old Classroom repo regarding this, but since we can no longer open issues regarding classroom, I guess the question is: is this a bug? Is this a feature?

Is everyone just creating two remote repositories, keeping one private, and keeping the solutions branch there?

Would be interested to know what people are doing to work around this. Thanks!


I am also interested in how to handle this gracefully.

Another related question: Will the student’s starting repo state also include the entire history of the template project. That is, can the student see all previous commits in the template. Or will the starting state be the first commit in their repo?

I keep two separate repos on GitHub, one for the assignment and one for the solution, and then set up both of them as separate remotes for the same local repo. This lets me, for example, rebase the solution on top of the assignment even though they’re two different repos on GitHub.

Here’s a crib sheet:

cd some-assignment

# First-time setup to make the separate solution repo a remote on the
# same local repo as the assignment:
git remote add solution <<SOLUTION REPO URL>>
git checkout solution/main  # or master, depending on your main branch name
git checkout -b solution

# To work on assignment locally, I work on the main branch and push to origin/main:
get checkout main
git push

# To work on solution locally, I work on the solution branch and push to solution/main:
git checkout solution
git push -u solution solution:main

I’d hardly call this “graceful,” but it’s at least workable. Would love to see GH Classrooms add the ability to copy only one branch to the students’ assignment repos!


I agree. We need this feature ASAP.

1 Like

@pcantrell Your idea of one repo with two remotes (one for each branch) is fabulous. I’ve started using this approach. It’s quite workable once you get the hang of it. Thank you!

1 Like

So glad I could help!

And I am shifting to this, as of today. Thanks so much for the crib sheet.

I wonder if instead of maintaining two repositories on Github 100% of the time and having to push changes to both, why not continue with a single repo including a solution branch and then when it comes time to disseminate an assignment, clone the template to a separate “assignment” template, drop the solution branch from the newly created template, and publish via Github Classroom.

When cloning to a new template, there is an option to copy branches other than master – as long as that remains unchecked, the cloned template consists of just the master branch.

I’ve tried this and it appears to work. Does anyone see any drawbacks to this approach?

I would doubt they can do that since Classrooms is a “wrapper” around GitHub. This is the way templates work in “normal” GH. Perhaps what they can do is delete all other branches after they use the template.

For my assignments I have a single repo with starter code on the master branch and solution on a solution branch. This repo (which is a template repo) lives in a “master” org for my course. Each term I create a new org for that year’s iteration of the course, and link a new classroom to this org.

To create an assignment using my assignment repo, I make a copy of it in this year’s org using “Use Template” feature. This only brings in the master branch. I can then use this copy of the repo as starter code for my assignment, since the solution branch is not included.

Works well for me, explaining it (not very well probably) makes it sound more convoluted than it actually is!

I think one issue with this is some assignments are spread out across multiple branches. It’s not the golden path or the way classroom wants you to work but copying the entire repo as is seems sensible.

When I teach, I do provide a solution branch, but I run workshops where there’s not a grade at the end.

The 2 repo solution is interesting… Or maybe a way to specify which branches you want copied over…

This is cool. It only copies the default branch if you use the UI. We’re explicitly bringing all branches over when a student accepts an assignment.