QTM 151 - Using GitHub and Jupyter Notebooks

Forking repositories and writing text and code

Danilo Freire

Emory University

05 September, 2024

What is git and what is GitHub? 💻

What is git?

  • git is a version control system that allows you to track changes in your code
  • It works similarly to Dropbox or Google Drive, but it is way more powerful
  • For instance, you can go back to any version of your code, see who made changes, collaborate with others, and merge different versions into a single one
  • git works in the command line, with graphical interfaces (e.g., GitHub Desktop), and integrated into code editors (e.g., VS Code)
  • git is a tool that you can use locally (only on your computer) or remotely (on a server like GitHub). If used online, it allows you to store your code in the cloud and collaborate with others (including yourself in the future!)
  • git can track changes in any type of file, not only code
  • In our case, we will use git to track changes in our Jupyter Notebooks too
  • While git has several commands, you will only need to use a few of them
  • The most common commands are git clone, git add, git commit, git push, and git pull. We will cover them in this lecture

What is GitHub?

  • GitHub is a website that hosts git repositories
  • A repository is a folder that contains your code and its history
  • GitHub allows you to share your code with others, collaborate, and contribute to other people’s projects
  • In this course, you will use GitHub to submit your assignments and access the course materials
  • GitHub offers many benefits to students, and you should consider using it for your projects and assignments even after this course
  • Please create an educational account at GitHub Education to access private repositories and GitHub Copilot, an AI pair programmer
  • GitHub has a graphical interface that makes it easy to navigate and interact with repositories
  • You can create repositories, branches, issues, pull requests, and more
  • GitHub also offers a feature called GitHub Pages, which allows you to create websites for free (such as this one!). But we will not cover it in this course
  • Think of GitHub as a social network for code, where you can follow people, star repositories, and contribute to open-source projects

Overview of a GitHub repository

Overview of a GitHub repository

  • Let’s take a closer look at our course’s repository
  • The repository is located at https://github.com/danilofreire/qtm151
  • You can see the files and folders in the repository, as well as when they were last modified
  • You can also see other buttons, such as Code, Issues, Pull requests, Actions, Projects, Wiki, and Security. You don’t need to worry about them now
  • If you click on Clone, you will get the URL to clone the repository to your computer. You can also download the repository as a ZIP file or open it in GitHub Desktop
  • If you click on Fork, you will create a copy of the repository in your GitHub account. You can then make changes to the repository
  • The Star button is used to bookmark the repository (think of a “like” button)

GitHub Desktop

  • GitHub Desktop is a graphical interface for git
  • It allows you to clone repositories, make changes, commit them, and push them to GitHub without using the command line
  • You can also create branches, merge them, and resolve conflicts
  • In our course, you will use GitHub Desktop to fork the course’s repository, update the course materials, and submit your assignments
  • Let’s install GitHub Desktop and clone the course’s repository
  • Please follow the instruction at https://github.com/apps/desktop

Forking the course’s repository 🍴

Forking the course’s repository

  • To fork the course’s repository, go to https://github.com/danilofreire/qtm151
  • Click on the Fork button in the top right corner (on the website!)
  • You will be redirected to your GitHub account, where you will see a copy of the course’s repository. Click okay to continue
  • This is important because you will now have your own copy of the course’s materials
  • You can make changes to your copy without affecting the original repository
  • Feel free to explore the repository and the files in it!

  • If you have already forked it, great!
  • You should see the same repository, but with your username instead of mine
  • For instance: https://github.com/your-username/qtm151
  • If you have that repository, you are ready to download it to your computer
  • Please download your forked repository, not the original one!

Downloading your forked repository with GitHub Desktop

  • Open GitHub Desktop and click on “Clone a Repository from the Internet” (the second button)
  • A window will open, then you click on “URL”
  • You just need to type your username and the repository name (e.g., your-username/qtm151)
  • Choose a local path to save the repository (a folder in your computer) and click on “Clone”
  • And that’s it! Now you have the folder in your computer! :)

How to make changes to your repository ✍️

Add, commit, and push

First, let’s add some text to the repository

  • To make changes to your repository, you need to follow three steps: add, commit, and push
  • git add (file) tells git to track changes in a file
  • git commit -m "message" saves the changes in the file. You always need to write a message when you make changes, so you can remember what you did
  • git push sends the changes to GitHub
  • You can also use GitHub Desktop to do these steps without using the command line, but this is what is happening behind the scenes
  • Let’s make a change to the repository and see how it works

  • You will see a screen like this on GitHub Desktop
  • You can either click on “Open the repository in your editor” or open the folder in your computer
  • Then, you can make changes to the files in the folder (add code, remove lines, etc)

Committing changes

  • I have made some changes to the repository in my computer
  • You can see the changes on GitHub Desktop. The lines in green are new lines, and the lines in red are removed lines
  • Now we have to commit the changes
  • Write a message in the little box at the bottom of the screen and click on “Commit to main”
  • The message should be short and describe what you did

Pushing changes to the repository

  • After committing the changes, you need to push them to GitHub
  • Click on “Push origin” to send the changes to your repository
  • You will see a progress bar at the bottom of the screen
  • Once the changes are pushed, you can see them on GitHub
  • Just go to your repository on GitHub and check the files!
  • You can also see the changes in the “History” tab on GitHub Desktop

And you’re done! :)

Updating the course’s repository 🔄

Updating the course’s repository

Pulling changes

  • Now that you know how to make changes to your repository, it is time to learn how to download new content that I add to the course’s repository
  • In git terms, pull or fetch are the commands that you use to update your local repository with new changes from the online repository
  • You can do this easily on GitHub Desktop: just click on Fetch origin
  • It will download the changes to your computer, and you can see them in the “History” tab
  • That’s all there is to it!

  • Please remember to pull changes before you start working on your assignments :)

Further readings

Tip

  • Please have a look at these resources if you have the time
  • And if you have any questions about git, GitHub, or GitHub Desktop, please let me know!

Should we talk about Jupyter Notebooks? 🤓 📓

What is a Jupyter Notebook?

  • Jupyter Notebook is an open-source format that allows you to create documents with code, equations, visualisations, and text
  • It is widely used in data science, machine learning, and scientific research
  • Jupyter Notebooks can be used with many programming languages, such as Python, R, Julia, and Scala, but it is most commonly used with Python
  • You can run code cells, see the output, and save the results in the same document
  • They are a great example of literate programming, where you can explain your code and show the results in the same place
  • And they are also intuitive and easy to use!

How to install Jupyter

  • If you have already installed Anaconda, you have Jupyter on your computer
  • You can also use Jupyter Notebooks online with Google Colab
  • Although you can create a Jupyter Notebook on Anaconda, I recommend you to use a code editor like VS Code to write your code
  • If you want to run it from the command line, you can use the command jupyter notebook in the terminal
  • More information about Jupyter Notebooks can be found here, and a tutorial can be found here

Writing text and code in Jupyter Notebooks ✍️ 💻

Writing text in Jupyter Notebooks

  • You can write text in Jupyter Notebooks using Markdown
  • Markdown is a lightweight markup language that allows you to format text easily
  • You can use headings, lists, links, images, tables, and more
  • Please refer to one of our tutorials for more information on Markdown
  • You can also use LaTeX to write equations in Jupyter Notebooks. More information can be found here
  • You can also include figures in Jupyter Notebooks using the following syntax: ![](path/to/figure.png)
  • Where path/to/figure.png is the directory and filename of the figure Markdown

Jupyter Markdown cheatsheet

Writing code in Jupyter Notebooks

  • You can write code in Jupyter Notebooks using code cells
  • It is the same Python code that you would write in a .py file, but with the results displayed below the cell
  • You can run the code cells by pressing Shift + Enter or clicking on the Run button
  • You can also write comments in the code cells using the # symbol

Connecting Jupyter with VS Code

  • This is the tricky part: For Notebooks to compile, you have to connect Anaconda with VS Code and run the Notebook from there
  • You can find more detailed instructions in our tutorial, but I will show you the main steps here
  • First, you need to install the Python and the Jupyter extensions in VS Code
  • Then, you need to select the Python interpreter in the bottom left corner of the screen
  • You have to select the base environment in Anaconda
  • Finally, you can open a Jupyter Notebook in VS Code and run it from there :)

Wrap-up 🚀

Takeaways

  • git and GitHub are great tools to store and share your code, and GitHub Desktop makes it easy to use them
  • You can fork the course’s repository, make changes, and submit your assignments using git and GitHub
  • Jupyter Notebooks allow you to easily write text and code in the same document, and it is one of the best tools for new programmers!
  • As always, if you have any questions, please let me know!
  • Drop me a message at if you need any help!