Background

This guide should be particularly useful for importing the Git repositories created and stored on school servers onto GitHub.

Steps

  1. Create a new (private) repository on GitHub. GitHub should give you a link in the following format:
    https://github.com/userName/ece297example.git
  2. Now go into your already created Git repository to add the GitHub repo as a “remote” of your git repo
    git remote add github https://github.com/userName/ece297example.git
  3. Push to the GitHub repo
    git push github master

Common Issues

Q: It will be an Academic Offence if someone copies my code. However, the GitHub repo was mistakenly created as a public one. Now that I have uploaded my code to the GitHub repo. How do I change the GitHub repo’s visibility?

A: You may follow steps below to change the visibility of your GitHub repo:

  1. Open the GitHub repo in your browser and go to “Settings”
    Where I can find “Settings” of some GitHub repository
  2. Under “Options”, scroll to the bottom of the page and you will be able to find the option to change the visibility of the repo.
    Where I can find “Change Visibility” of some GitHub repository

Q: When pushing to the GitHub repository, the push was rejected because the GitHub repo doesn’t accept any single file that is greater than 100M. However, the file has already been deleted in some commit, what should I do?

A: Once you committed some file to some git repo, it will be in the git history “forever” so that whenever you accidentally delete the file, you will still be able to recover it. To permanently delete the files greater than 100M from some repo, you may follow these steps:

# download the BFG tool into ~/Downloads
wget https://repo1.maven.org/maven2/com/madgag/bfg/1.14.0/bfg-1.14.0.jar --directory-prefix=$HOME/Downloads
# check your group number and replace cd-000 below
groups

# make a clone your repository because everything we do below could be VERY dangerous
cd ~
git clone --mirror ug251.eecg.utoronto.ca:/groups/ECE297S/cd-000/mapper_repo
 
# use BFG to remove the big file from the bare git repo
java -jar ~/Downloads/bfg-1.14.0.jar --strip-blobs-bigger-than 100M mapper_repo.git

# prune the git repo
cd mapper_repo.git
git reflog expire --expire=now --all && git gc --prune=now --aggressive

# set the "origin" remote to the github url and push
git remote set-url origin https://github.com/userName/ece297example.git
git push
Categories: ECE297

Junhao

Located in Markham, I am working as an Automotive Display Driver Engineer at Qualcomm Canada Inc. Previously, I graduated as a Computer Engineering undergraduate student at the University of Toronto and worked as an ECE297 TA there. As I once tutored ECE243 and APS105 at EngFastlane, now I am also providing tutoring service at TopLogic Inc.. I am proficient with C, C++, JavaScript and Python and familiar with PSQL, Java, Intel FPGA Verilog and ARM Assembly(V7). My interest is in Software Design and Development.

1 Comment

ECE297 Mapper Migration (2021) – Junhao · 1 May 2021 at 5:53 AM

[…] You are strongly recommended to backup your source files in a GitHub private repository, so that you don’t have to worry about losing your files in 2 or 3 years: https://junhao.ca/2021/04/09/import-an-existing-git-repository-onto-github/ […]

Leave a Reply

Avatar placeholder

Your email address will not be published. Required fields are marked *