Home > Enterprise >  How to change the default branch of a repo owned by CS50
How to change the default branch of a repo owned by CS50

Time:11-03

I'm taking Harvard's CS50-Web course and I'm trying to turn in my Capstone project. It is required that we push our project to the following exact branch:

web50/projects/2020/x/capstone

I have been pushing my code to this branch whenever I make changes to it. Recently, I realized I have been pushing my venv folder when I shouldn't be, so I added this to .gitignore, but the folder wasn't removed from the branch. So, I deleted the folder manually via GitHub's web interface. Now, whenever I try to push my project to this branch, it gets rejected because my local files are out of sync with the remote ones.

I thought I would just delete the branch and start anew, but it turns out web50/projects/2020/x/capstone is the default branch (I'm not sure how it got to be that way) and I am only able to delete branches that are not default. I see no way on GitHub to change the default branch. I can't access settings for the repo since it's not my repo.

I could just push all my files to a different branch, but the assignment has to be turned in at that exact branch (web50/projects/2020/x/capstone), otherwise it will not be graded.

I am new to git, if it's not obvious. Is there a way to change the default branch of a repo that isn't mine?

CodePudding user response:

First, update all origin/ refs to latest:

git fetch --all

Backup your current branch:

git branch backup-branch

Jump to the latest commit on origin/web50/projects/2020/x/capstone and checkout those files:

git reset --hard origin/web50/projects/2020/x/capstone

From here you should be able to merge your backup branch with your web50/projects/2020/x/capstone branch and push new changes up.

Check out this thread: https://stackoverflow.com/a/8888015/2255327

CodePudding user response:

TL;DR

Save any files you can't easily re-generate,1 somewhere outside your existing working tree. Then git fetch from the GitHub repository and merge or rebase. This may delete some of the files. That's OK because you already saved them where Git can't wreck them, so now you can put them back and continue using them.


1Except for a requirements.txt and the like, pretty much everything in .venv should be trivial to re-generate.


Long

To answer the question in the title and here:

... it turns out web50/projects/2020/x/capstone is the default branch (I'm not sure how it got to be that way) and I am only able to delete branches that are not default. I see no way on GitHub to change the default branch. I can't access settings for the repo since it's not my repo.

The owner of the repository on GitHub—or more precisely, anyone with "admin access"—is the person who can set the default branch. See this GitHub documentation page for details.

To answer the question you probably should have asked is a bit more involved:

Recently, I realized I have been pushing my venv folder when I shouldn't be, so I added this to .gitignore, but the folder wasn't removed from the branch. So, I deleted the folder manually via GitHub's web interface. Now, whenever I try to push my project to this branch, it gets rejected because my local files are out of sync with the remote ones.

Harvard should probably have a mini-course on source control here as there are several things you might need to un-learn at this point.

  • Related