Git Practice

We have created a third assignment for you to gain practice with the process of setting up your repository and with making and saving changes to the files in your repository.

This lab assumes you have completed the steps for Using Git with SSH.

Where should you do this lab?

You’ll be doing this lab on personal laptop in your first discussion section. You will need to connect to the Linux servers:

  • using the Department’s virtual desktop system,

  • using VSCode with SSH integration, or

  • by connecting to a CS server using SSH.

The CS techstaff provides detailed instructions on how to connect to a CS server using SSH.

Set up a repository

Complete the following steps to set up your repository.

  1. Using a browser, accept the invitation at the SOLO PRACTICE URL that we supplied on Ed.

  2. Set up an environment variable for use in this window. Replace replace_me_with_your_GitHub_username with your GitHub username.

    GITHUB_USERNAME=replace_me_with_your_GitHub_username
    
  3. Verify that the environment variable is correct:

    echo $GITHUB_USERNAME
    

    If the result is replace_me_with_your_GitHub_username or anything other your GitHub username, please redo the previous step.

    Note: This variable will only exist in your current terminal. If you open a new terminal, you will need to rerun the command to create the GITHUB_USERNAME variable.

  4. Navigate to your /home/USER/capp30121 directory, create a new directory named camp-3-$GITHUB_USERNAME, and change to the new directory:

    cd ~/capp30121
    mkdir camp-3-$GITHUB_USERNAME
    cd camp-3-$GITHUB_USERNAME
    
  5. Run this command to initialize a local repository:

    git init
    
  6. Now, run this command to connect the local repository to the repository that was created for you on GitHub when you accepted the invitation.

    git remote add origin git@github.com:uchicago-CAPP30121-aut-2021/camp-3-$GITHUB_USERNAME.git
    
  7. Next, we’ll connect your local repository to an upstream GitHub repository that we have seeded with code for this assignment. Run this command:

    git remote add upstream git@github.com:uchicago-CAPP30121-aut-2021/camp-3-initial-code.git
    
  8. Now, run this command:

    git pull upstream main
    

    This command pulls 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 the main branch of the upstream repository.

    If you run an ls, you will see that your directory now contains one file:

    README.md
    

    For future reference, if we need to fix a bug in the seed code or give you extra test cases, we will ask you to rerun the git pull upstream main command.

  9. Next, run this command to rename the default branch in your repository to main.

    git branch -M main
    
  10. Finally, run this:

    git push -u origin main
    

    This command pushed the current commit to GitHub. The arguments -u origin main tell Git that you want to push to your repository on GitHub (origin), and specifically the main branch. Git will remember and reuse these parameters when you run git push from this copy of the repository in the future.

Make a small change

  1. Using an editor, add your name to the README.md file. Make sure to save your changes and then add, commit, and push them to the server. If you need help remembering the commands to add, commit, and push, please ask for help or look back at the Introduction to Git lab.

  2. Finally, using an editor, create a new file name.py that contains the following:

    print("My name is", "YOUR_NAME_HERE")
    

    Save the file and then add, commit, and push it to the server.

  3. Run git status to make sure that your directory is in a clean state. That is, you should see something like this:

    $ git status .
    On branch main
    Your branch is up to date with 'origin/main'.
    
    nothing to commit, working tree clean
    
  4. Finally, log in to your GitHub account using a browser and take a look at the contents of the repository.

Working through this process again just to practice may seem tedious to some, but it is important to be able to execute these steps without needing to stop to think about each one.