Day 03: In-Class Assignment: Practice with Git and GitHub#

Student Identification#

Please do not modify the structure or format of this cell. Follow these steps:

  1. Look for the “YOUR SUBMISSION” section below

  2. Replace [Your Name Here] with your name

  3. If you worked with groupmates, include their names after your name, separated by commas

  4. Do not modify any other part of this cell

Examples:

Single student:  John Smith
Group work:      John Smith, Jane Doe, Alex Johnson

YOUR SUBMISSION (edit this line only):

✅ [Your Name Here]

Note:

  • Keep the “✅” symbol at the start of your submission line

  • Use commas to separate multiple names

  • Spell names exactly as they appear in the course roster

  • This cell has been tagged as “names” - do not modify or remove this tag

Table of Contents#

Learning goals for today#

By the end of class you should:

  1. Be a bit more comfortable using git on the command line so that you can clone and modify repositories

  2. Be able to create a repository on GitHub, clone it to your computer, and add, modify, and push changes to the repository. You should also be able to pull changes made by someone else.

  3. Understand how to give other people access to your GitHub repositories so that they can make changes as well.

Assignment instructions#

Work through the notebook with your group. Making sure to write all necessary code and answer any questions. Do your best to finish the assignment, but it’s OK if you don’t make it to the end.

This assignment is due by the end of class, and should be uploaded into the appropriate “In-Class assignments” submission folder. Submission instructions can be found at the end of the notebook.


Part 1. Review of pre-class assignment: thinking about version control and git#

Did anyone have any specific issues with the pre-class assignment?

Let’s take a moment to highlight some key concepts. Discuss with your table the following prompts and write down a brief definition of each of these concepts.

If you don’t feel like you have good working definitions yet, try doing a quick internet search to see if you can find a definition that makes sense to you.

🗒️ Task 1.1: Discuss what we are referring to when we talk about a code “repository”.

✏️ Answer:

🗒️ Task 1.2: Discuss what we mean when we talk about “version history” vs “version control”

✏️ Answer: - Write your disussion notes here.

🗒️ Task 1.3: Discuss why having a version control tool like git can be useful

✏️ Answer: - Write your disussion notes here.

🗒️ Task 1.4: Discuss the purpose/utility of the git clone command

✏️ Answer: - Write your disussion notes here.


Part 2. Reference guide for git commands#

In class we will be exploring git and some of the most common commands. Note there are a lot of other commands for using git as it is a very powerful tool. However, we can’t cover everything so this list just provides the most basic commands that let you create and contribute to a repository.

Checking out a git repository#

You’ve reviewed this one in the pre-class assignment and talked about it with your group. You need a URL for the repository. You also need to have permissions to access the repository. If the repository is public there is no problem. If the repository is private you will need a password, “personal access token”, or may need to set up an ssh key, which we may talk about at a later time.

  • git clone URL - Check out initial git repository

Creating a new git repository#

Creating a local/empty repository is easy. You can just use the “git init” command. Just make sure you run the command in the directory that you want to turn into a repository.

  • git init . - Create a new/empty repository. (the “.” is important because it indicates the current pwd!)

This only creates a local git repository. To sync this repository with a server (GitLab or GitHub) you need to create a “new project” on the website and follow the provided directions for syncing your local repository with the remote one.

Pulling in changes from the server.#

You got a glimpsed of this in the pre-class assignment and we’ll practice using it today. You can just run the “git pull” command to pull from the default repository:

  • git pull - Download changes from the central repository.

Or, if you want to pull from a different repository, you can specify the repository path:

  • git pull <path_to_remote_repository> - Download changes from another repository.

NOTE: git pull can be tricky! If you have modified any files and not committed them, those will be changed by the git pull. We’ll learn more information about merging in git later on.

Adding and Commiting a change#

The most common activity on a git repository is commiting a change. Typically you are either adding a new file or changing an existing file. The steps I almost always use are as follows:

  • git status - check to see what files are different

    • Existing files that have been changed will be listed under “Changes not staged for commit:”

    • New files that have not yet been added will be listed under “Untracked files:”

  • git add filename - Add new file(s) or changed file(s) to the current commit.

  • git status - check to make sure the files are included in the next commit.

    • These files will be listed under “Changes to be committed:”

  • git commit -m “Message about the changes” - Commit the changes to the repository while providing a description of the changes using the -m flag. You are now tracking the changes locally.

  • git commit -a -m Message about the changes” - Add modified files for staging with the -a flag and commit them with a message (-m) all in one command.

  • git push - Push all committed changes the changes to the server.

Some guidelines:

  • Commit early and often.

  • Do not commit binary files (unless you really mean it)

  • Do not “push” any changes that break something that was working.


Part 3. Practice downloading and exploring examples using git#

For this section, you’re going to practice cloning a variety of repositories from varying locations and use some of your new command line and git skills to poke around and see what the repositories contain. When you run into issues, reach out to your instructors and talk with your group.

3.1 Clone repositories from Github#

The GitHub website has massive collection of publicly availabe code and Jupyter-based examples. We are going to download a couple of examples, see if we can get them working, and explore them a bit with our new git skills:

Setting up a GitHub account#

If you haven’t already, you need to set up an account on GitHub. Go to and sign up for an account using your “@msu.edu” email address. For consistency, it is also useful if you make your username match your MSU NetID.

Note: After creating this account and when you start using git, you may notice that you will need to log into your github account. There should be prompts that come up when first trying to use git. However, if they do not pop-up, you may need to add your account information manually. You can do this by the commands found below

git config --global user.name "Your name here"
git config --global user.email "your_email@example.com"

Hopefully you have got everything set up on Github, let’s dive in!

🛑 STOP#

check

🗒️ Task 3.1.1: Make a directory called “repositories” in your “CMSE802” folder (if you haven’t already done so). Go into the “repositories” directory.

🗒️ Task 3.1.2: Now run the following command:

git clone https://github.com/domagal9/MSU-LaTeX-Templates.git

🗒️ Task 3.1.3: Take a second and look through this git repository. What does this repo do? Discuss with your groupmates.

✏️ Answer:

🗒️ Task 3.1.3: How would you use this repo?

✏️ Answer:

🗒️ Task 3.1.4: Try using git log to explore the version history of this repository, then answer these questions:

  1. What information does git log provide you with?

  2. Who is the author of this repository? (First, Last and email)

  3. What date and time was the last commit?

  4. What is the message in the commit?

✏️ Answer:

3.2 Finding and working with repos on your own#

🗒️ Task 3.2.1 - In GitHub, look for a repo that might be useful to you. For example, try searching for the repo of a research group you are interested in, repo of a class or a class topic. Put the name of the repo you found and those of your groupmates below

✏️ Answer:

🗒️ Task 3.2.2: Explore the repository, what is the purpose of repository you found?

✏️ Answer:

🗒️ Task 3.2.3: Who is the author of this repository and where are they located? How did you figure this out?

✏️ Answer:

🗒️ Task 3.2.4: Without cloning the repository determine when this repository was last updated and write the commit message below

✏️ Answer:

Reflecting on accessing publicly available git repositories#

As you move forward through the course, remember that the internet has a wealth of information and interesting code. When you embark on a new project, it can be worth hunting around to see if someone has some something similar that you can leverage to accomplish your goals. However, any time you make use of someone else’s publicly available code, make sure to cite them in your code and link back to the original source! Failing to give credit where credit is due is not only considered plagiarism but goes against the ideal ethics for a productive open-source code community.


Part 4. Let’s “Git” practicing: setting up and managing a new GitHub repository#

To start out on this activity, you’ll do a bit of work individually to set up, clone, modify, and push to a GitHub-hosted git repository that you are the owner of. By going through this process, you’ll be continuing to play around with git and to get some practice for when you need to interact with GitHub repositories in the future, including for your group project this semester!

4.1 Building a testing repo#

🗒️ Task: 4.1.1: Go to and individually create a new private git repository. Note that all GitHub repositories will default to being public, but for right now we want to create a sandbox for you to play in that isn’t shared to the whole world :)

Call this repository USERNAME_git_testing where USERNAME is replaced by your MSU NetID (the part of your email address before the “@”).

You should also initialize your repository with a “README” file - you’ll be editing that momentarily.

Note any problems you had with the above steps (or any questions) below. Check in with your group to see if they can help troubleshoot any issues you run into.

✏️ Answer:

🗒️ Task: 4.1.2: Clone this new repository into your ~/CMSE802/repositories directory.

MAKE SURE YOU HAVE YOUR PERSONAL ACCESS TOKEN.#

Information on how to get your PAT can be found in the pre-class assignment (there is a video that guides you through the process).

Note any problems you had with the above step (or any questions) here. Check in with your group to see if they can help troubleshoot any issues you run into.

✏️ Answer:

🗒️ Task: 4.1.3: Once you’ve cloned the repository, open the “README.md” file that should have been created inside of the repository folder when you set it up on GitHub. Add the following information to the README file:

  • Name

  • Email Address

  • What is your department?

  • Where are you from?

  • What is your programming background?

Note: The README is a Markdown file, so the same techniques for formatting the text that work in Jupyter notebooks will also work in this file, but you won’t see the formatting until you push it back to GitHub.

Note any problems you had with the above step (or any questions) in the cell below. Check in with your group to see if they can help troubleshoot any issues you run into.

✏️ Answer:

🗒️ Task: 4.1.4: commit these changes to your repository. Check your commits with git log. Finally, push the changes back to the central repository on GitHub.

Note any problems you had with the above step (or any questions) in the cell below. Check in with your group to see if they can help troubleshoot any issues you run into.

✏️ Answer:

🗒️ Task: 4.1.5: Go check the GitHub website for your new repository and confirm that the changes to the README file show up – they should be on the homepage for your repository now.

Note any problems you had with the above step (or any questions) in the cell below. Check in with your group to see if they can help troubleshoot any issues you run into.

✏️ Answer:

4.2 Sharing repos#

🗒️ Task: 4.2.1: Create a new file in your repository and call it group_information.md. To start the file, add a Markdown heading at the top like so:

# Group member names and information

Annotate any problems you had with the above step (or any questions) in the cell below. Check in with your group to see if they can help troubleshoot any issues you run into.

✏️ Answer:

🗒️ Task: 4.2.2: Add and commit this new file to your repository and push it back up to GitHub (confirm that it shows up on the web once you’ve done this).

Annotate any problems you had with the above step (or any questions) in the cell below. Check in with your group to see if they can help troubleshoot any issues you run into.

✏️ Answer:

🗒️ Task: 4.2.3: Share your GitHub username with your group members and ask your group members for their usernames as well. Once you have their usernames, you need to add them as collaborators on your new repository. (If you’re unsure of how to do this, try googling it!)

Annotate any problems you had with the above step (or any questions) in the cell below. Check in with your group to see if they can help troubleshoot any issues you run into.

✏️ Answer:

🗒️ Task: 4.2.4: Share a direct link to your GitHub repository so that your group mates can access it easily. You can share this information by starting a group chat on Teams. Then, ask your group members to try cloning your repository.

Annotate any problems you had with the above step (or any questions) in the cell below. Check in with your group to see if they can help troubleshoot any issues you run into.

✏️ Answer:

🗒️ Task: 4.2.5 Every group member should add their name and MSU email address to the group_information.md file. Save the file and then commit your changes.

Annotate any problems you had with the above step (or any questions) in the cell below. Check in with your group to see if they can help troubleshoot any issues you run into.

✏️ Answer:

🗒️ Task: 4.2.6: Try pushing the changes you’ve made to your group members’ repositories so that they get your contact information.

NOTE: You might get a message from git that your attempt to push changes has been rejected. This tends to happen if someone else pushes changes before you did. In a first attempt to resolve this, you should do a git pull to see if you can successfully merge their changes with your own. If this is successful, you should then be able to push your changes. Sometimes, however, you’ll get a “merge conflict” which is an indication that your changes are crashing into someone else changes. This is a bit of a teaser for next class; for now, try your best to make sense of what a merge conflict is and talk things through with your group, ask instructors for help, and consult the internet.

✏️ Answer:

🗒️ Task: 4.2.7: Do a git pull for your original repository so that you have the contact information from your group members. If done correctly, eventually each repository will have the names and emails for all of the team members in the group_information.md file. Be patient at this point, getting used to working collaborative on GitHub repositories takes time!

✏️ Answer:


Wrapping up#

Once everyone has managed to set up their own repository and has successfully added their group members as collaborators, you’re done with this activity! If you have extra time, feel free to explore the GitHub website a bit more and see what other features it has to offer. If you have questions about anything that came up during this activity, make sure to ask your instructors about them!


Congratulations, you’re done with your in-class assignment!#

Now, you just need to submit this assignment by uploading it to the course Desire2Learn web page for today’s in-class assignment submission folder. (Don’t forget to add all of the appropriate names in the first cell).

© Copyright 2024, Department of Computational Mathematics, Science and Engineering at Michigan State University