Working with upstream repositories
For each assignment in CAPP 30121, we provide some initial code that you must upload to your repository. We’ll use what is known as an upstream repository to distribute this code.
To gain practice with this process, follow the steps below. These steps are similar to what you did at the beginning of the first Git lab with a couple of extra commands thrown in.
-
Using a browser, accept the invitation at the CAMP-2 URL that we supplied on Ed.
-
Navigate to your
/home/USER/capp30121
directory and creating a new directory namedcamp-2-YOUR_GITHUB_USERNAME
(where, as usual,YOUR_GITHUB_USERNAME
is replaced with your YOUR_GITHUB_USERNAME).cd ~/capp30121 mkdir camp-2-YOUR_GITHUB_USERNAME cd camp-2-YOUR_GITHUB_USERNAME
-
And then run the following commands using your GitHub username in place of
YOUR_GITHUB_USERNAME
in the second command.git init git remote add origin git@github.com:uchicago-CAPP30121-aut-2022/camp-2-YOUR_GITHUB_USERNAME.git git remote add upstream git@github.com:uchicago-CAPP30121-aut-2022/camp-2-initial-code.git git pull upstream main git branch -M main git push -u origin main
If you run an
ls
, you will see that your directory now contains two files:hello.py README.md
If you are wondering, here is what these commands do (line-by-line):
-
git init
: Initialize a local repository in the current working directory. -
git remote add origin git@github.com:uchicago-CAPP30121-aut-2022/camp-2-GITHUB_USERNAME.git
: Connect the local repository to the repository that was created for you on GitHub when you accepted the assignment invitation. -
git remote add upstream git@github.com:uchicago-CAPP30121-aut-2022/camp-2-initial-code.git
: Connect your local repository to an upstream GitHub repository that we have created and seeded with code for this assignment. -
git pull upstream main
: Pull the seed code from the upstream repository into your local copy of the repository and package it into a commit. Notice that the pull command indicates that code should be pulled from themain
branch of the upstream repository. -
git branch -M main
: Rename the branch for your local repository frommaster
, a legacy name, tomain
, the preferred name. -
git push -u origin main
: Push the current commit to GitHub. The arguments-u origin main
tell Git that you want to push from the local copy (origin
) to themain
branch on GitHub. Git will remember and reuse these parameters when you rungit push
from this copy of the repository in the future.
From here on out, you can add, commit, pull, and push as usual to manage your repository. In the (hopefully) unlikely event that we need to fix a bug in the code that we provide, we’ll update the upstream repository and ask you to run git pull upstream main
, to pull changes to the upstream code into your local copy.