Is it possible to add a new file to a forked repo?

I want to be able to add a file, or really a folder with more than one file to a repository that students have already forked and worked on. Is this possible?

Here is a more detailed description of what I am doing:

  • I have starter code for student in a repository, lets call that “lab”
  • every student forks that code so they wind up with jane/lab
  • The repo holds folders like week1, week2, week3
  • two weeks go by and I want to make changes to week3 before they start on it, or maybe I want to add a week4
  • The students have already been working on the lab and pushing changes so that I can review their code.
  • How can I push out additional files, or changes, without pulling their code changes?
1 Like

There is no way to push code to another person’s git repo unless they give you write access.

This seems like a great way to teach proper git usage. Perhaps require that they learn how to pull from your remote repo and push the updated changes to their own repo? That can be how you “hand out” assignments each week.

Your last option would be to open a PR into each student’s repo.

1 Like

I agree with @richiepreece. The best thing for you to do, probably, would be to upload a repository and to keep uploading (pushing) changes to that repo. Every once in a while you should ask your students to pull the new content from your repo so that they are up to date.
Forking isn’t really meant for this kind of behavior as far as I’m concerned. You should fork a repo when you want a copy of a repo from someone else so that you can perform changes in this repo. (This is of course a simplification because you can do a lot more with forks).
Hope it helps!

I don’t want to push changes to my students’ repositories, only to make changes and additions available to them

So, if you want them to be available, then I’d simply push them to your master repo and let the students pull from there. Since it was forked, it should be easy for them to pull and merge back into their repos from yours.

I will test it out… so far it didn’t seem to act that way.

So, for example, if I forked your repo to, on the command line I could do:

git clone
cd mrodonell
git remote add mrodonnellrepo

This adds a remote repo (will be read only). Then the student needs to update their repo by simply:

git pull mrodonnellrepo branch

This will pull the most recent changes that you’ve added

Here’s how I have my students get updates.

Teacher’s Repo:
Student(s) visit above site and click Fork, which creates:
Student’s Repo:

Student should then clone the repo locally:

git clone
cd git_101_class
git remote add upstream

After the teacher updates the repo (master) branch, each student should do the following:

git checkout master
git pull upstream master



@jasonnoble Keep in mind that you don’t HAVE to be on the master branch to pull a branch from upstream though

@MrODonnell Be sure to follow the instructions per @jasonnoble .

If you are asking if there is a way to do this via the GitHub interface, I believe this approach still works.

The most appropriate way to do this for a class that should understand Git well is for you to, as others have said, is to update your repo, and make them fetch and either merge, rebase, or cherry-pick the commit(s) in. Cherry-picking is probably the best solution, since merging and rebasing aren’t really designed for a workflow like this. (You could probably provide them with a script to do so.)

The easiest way for them is for you to either:

  1. open PRs on every student’s repo with the given commit, which you could script with Hub, or
  2. push the commits to every student’s repo.

In both cases the students will have to pull down your commits; there’s really no way to get around that.

I wonder if this is a common enough use case where the Classroom interface should support opening PRs into every student’s repo - I’ve ran into this two or three times this semester.

Last semester we found out that it is actually possible to push to some else’s (student’s) fork.

We create a private repo for each student and add them as collaborators with read-only access, so they have to fork it, push their changes and create pull requests to “submit” their code. As owners of the org/repo we were able to push to their forks. We did this to push new branches to their forks or fix problems if they messed up something… (this was more of an introductory level class and most students didn’t really want to get too much into git at that time, just get their assignments submitted with as little extra work as possible)

Not sure if that is a bug or “works as intended” :wink:

1 Like